/* Date: 25.02.2019 * Time: 21:45 */
//

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Example
{
	public static void Main (string[] args)
	{
# if ( ! ONLINE_JUDGE )
		StreamReader sr = new StreamReader ("C:\\TRR\\2019\\Task\\07 Codeforces\\037\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2019\\Task\\07 Codeforces\\037\\A.OUT");
# endif

		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

		int n;
		string s;

# if ( ONLINE_JUDGE )
		n = int.Parse (Console.ReadLine ());
		s = Console.ReadLine ();
# else
		n = int.Parse (sr.ReadLine ());
		s = sr.ReadLine ();
		sw.WriteLine ("*** n = " + n);
		sw.WriteLine ("*** a = " + s);
# endif

		int [] a = new int [n];
		string [] ss = s.Split (' ');
		int kp = 0, kn = 0;
		for ( int i=0; i < n; i++ )
		{
			a [i] = int.Parse (ss [i]);
			if ( a [i] > 0 )
				kp ++;
			else if ( a [i] < 0 )
				kn ++;
		}

		int d = 0;
		if ( kp >= n - kp )
			d = 1;
		if ( kn >= n - kn )
			d = -1;

# if ( ONLINE_JUDGE )
		Console.WriteLine (d);
# else
		sw.WriteLine (d);
		sw.Close ();
# endif

	}
}


using System;

namespace FunctionalProgramming
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] n = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int price = n[0];
            int counter = 0;
            for (counter = 1; ; counter++)
            {
                if (price % 10 == 0)
                {
                    break;
                }
                else if (price % 10 - n[1] == 0) break;

                price = n[0] * (counter + 1);
            }
            Console.WriteLine(counter);
        }
    }
}


// A Dynamic Programming based
// C# program to find minimum
// number operations to
// convert str1 to str2
using System;
using System.Collections.Generic;
using System.Linq;
class GFG
{

    public static void Main()
    {
        List<ulong> arr = Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToList<ulong>();
        var op = Console.ReadLine().Split(' ').ToArray();
        Console.Write(SmallestNumber(arr, op, 0, ulong.MaxValue));
    }

    public static ulong SmallestNumber(List<ulong> arr, string[] ope, int opeCount, ulong min)
    {

        if (arr.Count == 1)
            return arr[0];

        for (int i = 0; i < arr.Count; i++)
        {
            for (int j = i + 1; j < arr.Count; j++)
            {
                if (ope[opeCount] == "+")
                {
                    var listNew = new List<ulong>(arr);
                    var tmp = listNew[i] + listNew[j];
                    listNew.RemoveAt(j);
                    listNew.RemoveAt(i);
                    listNew.Add(tmp);
                    min = Math.Min(min, SmallestNumber(listNew, ope, opeCount + 1, min));
                }
                if (ope[opeCount] == "*")
                {
                    var listNew = new List<ulong>(arr);
                    var tmp = listNew[i] * listNew[j];
                    listNew.RemoveAt(j);
                    listNew.RemoveAt(i);

                    listNew.Add(tmp);
                    min = Math.Min(min, SmallestNumber(listNew, ope, opeCount + 1, min));
                }
            }
        }

        //min = Math.Min(min1, min2);
        return min;
    }
}


using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int i = a[0]-1; i > a[0]-1-a[1]; i--)
            {
                b[i] = a[2];
            }

            Console.WriteLine(b.Sum());
        }
    }
}


using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string data = Console.ReadLine();
            data = data.Remove(0, 1);
            int num = Convert.ToInt32(data);
            if (num % 2 == 0)
                Console.WriteLine("0");
            else Console.WriteLine("1");
        }
    }
}


using System;
// you can also use other imports, for example:
using System.Collections.Generic;
using System.Linq;
using System.IO;

public class HelloWorld
{

    public static void Main(string[] args)
    {
        var n = Convert.ToInt64(Console.ReadLine());
        Console.WriteLine(n / 2520);
    }

}


using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main() {
        int[] arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int y = arr[0]+1;
        int b = arr[1];
        int r = arr[2]-1;

        Console.WriteLine(Math.Min(Math.Min(r,b),y)*3);
    }
}


using System;
using CompLib.Mathematics;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();

        var ans = ModInt.Pow(ModInt.Pow(2, m) - 1, n);
        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s = Console.ReadLine();
                while (s.Length == 0)
                {
                    s = Console.ReadLine();
                }

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    #region ModInt

    /// <summary>
    /// [0,<see cref="Mod"/>) までの値を取るような数
    /// </summary>
    public struct ModInt
    {
        /// <summary>
        /// 剰余を取る値．
        /// </summary>
        public const long Mod = (int) 1e9 + 7;

        /// <summary>
        /// 実際の数値．
        /// </summary>
        public long num;

        /// <summary>
        /// 値が <paramref name="n"/> であるようなインスタンスを構築します．
        /// </summary>
        /// <param name="n">インスタンスが持つ値</param>
        /// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
        public ModInt(long n)
        {
            num = n;
        }

        /// <summary>
        /// このインスタンスの数値を文字列に変換します．
        /// </summary>
        /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
        public override string ToString()
        {
            return num.ToString();
        }

        public static ModInt operator +(ModInt l, ModInt r)
        {
            l.num += r.num;
            if (l.num >= Mod) l.num -= Mod;
            return l;
        }

        public static ModInt operator -(ModInt l, ModInt r)
        {
            l.num -= r.num;
            if (l.num < 0) l.num += Mod;
            return l;
        }

        public static ModInt operator *(ModInt l, ModInt r)
        {
            return new ModInt(l.num * r.num % Mod);
        }

        public static implicit operator ModInt(long n)
        {
            n %= Mod;
            if (n < 0) n += Mod;
            return new ModInt(n);
        }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(ModInt v, long k)
        {
            return Pow(v.num, k);
        }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1)
                    ret = ret * v % Mod;
            return new ModInt(ret);
        }

        /// <summary>
        /// 与えられた数の逆元を計算します．
        /// </summary>
        /// <param name="v">逆元を取る対象となる数</param>
        /// <returns>逆元となるような値</returns>
        /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
        public static ModInt Inverse(ModInt v)
        {
            return Pow(v, Mod - 2);
        }
    }

    #endregion

    #region Binomial Coefficient

    public class BinomialCoefficient
    {
        public ModInt[] fact, ifact;

        public BinomialCoefficient(int n)
        {
            fact = new ModInt[n + 1];
            ifact = new ModInt[n + 1];
            fact[0] = 1;
            for (int i = 1; i <= n; i++)
                fact[i] = fact[i - 1] * i;
            ifact[n] = ModInt.Inverse(fact[n]);
            for (int i = n - 1; i >= 0; i--)
                ifact[i] = ifact[i + 1] * (i + 1);
            ifact[0] = ifact[1];
        }

        public ModInt this[int n, int r]
        {
            get
            {
                if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
                return fact[n] * ifact[n - r] * ifact[r];
            }
        }

        public ModInt RepeatedCombination(int n, int k)
        {
            if (k == 0) return 1;
            return this[n + k - 1, k];
        }
    }

    #endregion
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Numerics;

namespace cf420
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_cf420B();
        }

        public static void solve_cf420B()
        {
            long[] mb = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            long m = mb[0];
            long b = mb[1];

            List<KeyValuePair<long, long>> xy = new List<KeyValuePair<long, long>>();

            for (long x = 0; x < (m * b) + 1; x++)
            {
                long xm = x / m;
                if (x % m == 0)
                {
                    xy.Add(new KeyValuePair<long, long>(x, -xm + b));
                }
            }

            long max = -1;
            for (int i = 0; i < xy.Count; i++)
            {
                long l = Math.Min(xy[i].Key, xy[i].Value);
                long n = Math.Max(xy[i].Key, xy[i].Value);

                long sum = 0;

                for (long j = 0; j <= l; j++)
                {
                    sum += ((n + 1) * (j + n + j)) / 2;
                }
                max = Math.Max(max, sum);
            }

            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace ConsoleApplication1 {
    struct Pair {
        public int X, Y;
        public Pair(int x, int y) {
            X = x;
            Y = y;
        }
        public override string ToString() {
            return string.Format("{0} {1}", X, Y);
        }
    }

    class Graph : List<List<int>> {
        public Graph(int num) : base(num) {
            for (int i = 0; i < num; i++) {
                this.Add(new List<int>());
            }
        }
    }

    class Program {
        static int n, m, k, t, ans;
        static TextReader input;
        static int[] f;
        static bool[] u1, u2;
        static Graph g, rg;
        static void Main(string[] args) {
#if TESTS
            Stopwatch sw = new Stopwatch();
            sw.Start();
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.WriteLine();
            Console.WriteLine("Milliseconds: {0}", sw.ElapsedMilliseconds);
            Console.ReadLine();
#endif
        }

        #region read helpers
        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static List<int> ReadIntList() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }

        #endregion

        static void Solve() {
            int[] a = ReadIntArray();
            n = a[0];
            m = a[1];
            g = new Graph(n);
            rg = new Graph(n);
            u1 = new bool[n];
            u2 = new bool[n];
            f = ReadIntArray();
            for (int i = 0; i < m; i++) {
                int[] b = ReadIntArray();
                g[--b[0]].Add(--b[1]);
                rg[b[1]].Add(b[0]);
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 1 && !u1[i]) {
                    Bfs1(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2 && !u2[i]) {
                    Bfs2(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (u1[i] && u2[i])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }

        static void Bfs1(int v) {
            u1[v] = true;
            Queue<int> q = new Queue<int>();
            q.Enqueue(v);
            while (q.Count > 0) {
                int u = q.Dequeue();
                foreach (int i in g[u]) {
                    if (!u1[i]) {
                        u1[i] = true;
                        q.Enqueue(i);
                    }
                }
            }
        }

        static void Bfs2(int v) {
            u2[v] = true;
            Queue<int> q = new Queue<int>();
            q.Enqueue(v);
            while (q.Count > 0) {
                int u = q.Dequeue();
                foreach (int i in rg[u]) {
                    if (!u2[i]) {
                        u2[i] = true;
                        if (f[i] != 1)
                            q.Enqueue(i);
                    }
                }
            }
        }

        static void Dfs1(int v) {
            u1[v] = true;
            foreach (int i in g[v]) {
                if (!u1[i]) Dfs1(i);
            }
        }

        static void Dfs2(int v) {
            u2[v] = true;
            if (f[v] == 1) return;
            foreach (int i in rg[v]) {
                if (!u2[i]) Dfs2(i);
            }
        }

        static int[] Count_Sort(int[] a, int k) {
            int n = a.Length;
            int[] b = new int[n];
            int[] c = new int[k];
            for (int i = 0; i < n; ++i)
                ++c[a[i]];
            for (int i = 1; i < k; ++i)
                c[i] += c[i - 1];
            for (int i = n - 1; i >= 0; --i) {
                b[c[a[i]] - 1] = a[i];
                --c[a[i]];
            }
            return b;
        }

        static void Radix_Sort(int[] a, int k) {
            int n = a.Length;
            int repeats = 32 / k;
            int size = 1 << k;
            int mask = size - 1;
            for (int i = 0; i < repeats; ++i) {
                int[] c = new int[size];
                int[] b = new int[n];
                for (int j = 0; j < n; ++j) {
                    int r = (a[j] & (mask << (i * k))) >> (i * k);
                    ++c[r];
                }
                for (int j = 1; j < size; ++j)
                    c[j] += c[j - 1];
                for (int j = n - 1; j >= 0; --j) {
                    int r = (a[j] & (mask << (i * k))) >> (i * k);
                    b[c[r] - 1] = a[j];
                    --c[r];
                }
                Array.Copy(b, a, n);
            }
        }
    }

    public static class Extensions {
        public static void Print<T>(this IEnumerable<T> e) {
            foreach (T item in e) {
                Console.Write("{0} ", item);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    public class Given_Length_and_Sum_of_Digits
    {
        public static bool Can(int m, int s)
        {
            if (m == 0)
            {
                return s == 0;
            }
            return s >= 0 && s <= m * 9;
        }
        public static string Calculate(int m, int s)
        {
            var max = "";
            var min = "";

            if (!Can(m, s) || (s==0 && m!=1))
            {
                return "-1 -1";
            }
            var currentS = s;
            while (min.Length != m)
            {
                for(var i = 0; i <= 9; i++)
                {
                    if(min.Length ==0 && i == 0 && m!=1)
                    {
                        continue;
                    }

                    if(Can(m - min.Length - 1, currentS - i))
                    {
                        min += i.ToString();
                        currentS -= i;
                        break;
                    }
                }
            }
            currentS = s;
            while (max.Length != m)
            {
                for (var i = 9; i >= 0; i--)
                {
                    if (max.Length == 0 && i == 0 && m != 1)
                    {
                        continue;
                    }

                    if (Can(m - max.Length - 1, currentS - i))
                    {
                        max += i.ToString();
                        currentS -= i;
                        break;
                    }
                }
            }

            return min.ToString() + " " + max.ToString();
        }
        public static void Main()
        {
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(Calculate(a[0], a[1]));
        }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

                     int numberOfCards = Convert.ToInt32(Console.ReadLine());
                    int inputNumberCard = 0;
                    List<int> Cards = new List<int>();
                    List<int> Temp = new List<int>();
                    for (int i = 0; i < numberOfCards; i++)
                    {
                    inputNumberCard = Convert.ToInt32(Console.ReadLine());
                    Cards.Add(inputNumberCard);
                    }
                    foreach (var el in Cards.Distinct())
                    {
                     Temp.Add(Cards.Where(s => s == el).Count());
                    }
            if ((numberOfCards-Temp[0]) == Temp[0])
                    {
            var x = SearchDuplicateInList(Cards);
                if (x.Count == 2 && x[0] != x[1])
                    {
                    Console.WriteLine("YES");
                    Console.Write($"{x[0]} {x[1]}");
                    }
                    else
                    { Console.WriteLine("NO");}
                    }
                    else
                    { Console.WriteLine("NO"); }
         }
        static List<int> SearchDuplicateInList(List<int> list)
        {
            List<int> result = new List<int>();
            foreach (var s in list)
            {
                if (!result.Contains(s))
                    result.Add(s);
            }
            return result;
        }

   }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nums = Console.ReadLine().Split();
            int n,c,max;
            n = Convert.ToInt32(nums[0]);
            c = Convert.ToInt32(nums[1]);
            nums = Console.ReadLine().Split();
            int[] ar=new int[n];
            int[] m = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = Convert.ToInt32(nums[i]);
            for (int i = 0; i < n-1; i++)
                m[i] = ar[i] - ar[i + 1] - c;

            max=m[0] ;
            for (int i = 0; i < n; i++)

                if (m[i] > max)
                    max = m[i];
            Console.WriteLine(max);
            Console.ReadLine();

        }
    }
}