using System;
using System.Linq;
using CompLib.Util;
using System.Threading;

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

        for (int a = 0; a <= n; a++)
        {
            int b = n - a;
            long t = (long) (a + 1) * a / 2 - b;
            if (t == k)
            {
                Console.WriteLine(b);
                return;
            }

            if(t > k) return;
        }
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

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;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

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

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        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();
    }
}


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

using static System.Console;

public class Test
{
    static int Sum(int n)
    {
        return (2 + n - 1) * n / 2;
    }

    static int Res(int i, int n)
    {
        return Sum(i) - n + i;
    }

    static int Mid(int left, int right)
    {
        return (int)Math.Floor((double)(left + right / 2));
    }

    public static void Main()
	{
        var line1 = ReadLine().Split();
        int n = int.Parse(line1[0]);
        int k = int.Parse(line1[1]);

        int left = 1;
        int right = n;
        int mid = Mid(left, right);
        while(Res(mid, n) != k)
        {
            if(Res(mid, n) > k)
            {
                right = mid;
            }
            else
            {
                left = mid;
            }

            mid = Mid(left, right);
        }

        WriteLine(Sum(mid) - k);
	}
}


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

namespace Konfeti
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var n = int.Parse(s[0]);
            var k = int.Parse(s[1]);

            var i = 1;
            var ans = -1;
            while (ans==-1)
            {
                var eat = n - i;
                if (i * (i + 1) / 2 - eat == k)
                {
                    ans = eat;
                }

                i++;
            }

            Console.Write(ans);

        }
    }
}


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

namespace Task_02
{
    class Program
    {
        static void Main(string[] args)
        {
            var ints = Console.ReadLine().Split(null).Select(int.Parse).ToArray();
            int n = ints[0];
            int k = ints[1];

            var i = 0;
            while (true)
            {
                if ((n - i) * (n - i + 1) / 2  - i == k)
                    break;
                i++;
            }

            Console.WriteLine(i);
        }
    }
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt64);
            long n = nk[0], k = nk[1];
            int kq = 0;
            long ts = n * n + n - 2 * k;
            while (true)
            {
                if(ts%(2*n+3-kq)==0&&ts/(2*n+3-kq)==kq)
                {
                    Console.WriteLine(kq);
                    break;
                }
                kq++;
            }

        }
    }
}


using System;
using CompLib.Util;

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

        // 最初飴を1つ入れる

        // 飴を1つ食べる
        // 前回入れる操作した個数+1入れる

        // n回操作してk個飴入ってる 食べた個数

        // 食べた x回

        for (long x = 0; x <= n; x++)
        {
            long y = n - x;
            long t = (y + 1) * y / 2 - x;
            if (t == k)
            {
                Console.WriteLine(x);
                return;
            }
        }
    }

    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;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

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

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        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();
    }
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt64);
            long n = nk[0], k = nk[1];
            long ts = n * n + n - 2 * k;
            long kq = ts / (2 * n + 3);
            while (true)
            {
                if(ts%(2*n+3-kq)==0&&ts/(2*n+3-kq)==kq)
                {
                    Console.WriteLine(kq);
                    break;
                }
                kq++;
            }

        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = new int[2];

            string str = Console.ReadLine();
            string s = "";

            for(int i = 0; i < str.Length; i++)
            {
                if(str[i]==' ')
                {
                    array[0] = Convert.ToInt32(s);
                    s = "";
                }
                else
                {
                    s += str[i];
                }
            }
            array[1] = Convert.ToInt32(s);

            int l,m,mid;
            l = array[0];
            m = 1;

            while (true)
            {
                mid = (l + m) / 2;
                if ((1 + mid) * mid / 2 - (array[0] - mid) > array[1])
                {
                    l = mid -1;
                }
                if ((1 + mid) * mid / 2 - (array[0] - mid) < array[1])
                {
                    m = mid +1;
                }

                if ((1 + mid) * mid / 2 - (array[0] - mid) == array[1])
                {
                    break;
                }

            }

            Console.WriteLine(array[0] - mid);

       //  Console.Read();

        }
    }

}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = new int[2];

            string str = Console.ReadLine();
            string s = "";

            for(int i = 0; i < str.Length; i++)
            {
                if(str[i]==' ')
                {
                    array[0] = Convert.ToInt32(s);
                    s = "";
                }
                else
                {
                    s += str[i];
                }
            }
            array[1] = Convert.ToInt32(s);

            int j = 1;
            while ((1 + j) * j / 2 - (array[0] - j) != array[1])
            {
                j++;
            }
            Console.WriteLine(array[0] - j);

        // Console.Read();

        }
    }

}


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

namespace Codeforces574
{
    class Program2
    {
        static void Main()
        {
            //l=入れた回数
            // s = n - l
            // l = n - s
            //(n-s)*(1+n-s)/2 - s - k = 0
            var input = Console.ReadLine().Split(' ').Select(int.Parse);
            var n = input.First();
            var k = input.Skip(1).First();

            var A = -2 * n - 2 * k;
            var l = (int)(-3 + Math.Sqrt(9 - 4 * A)) / 2;
            var ans = n - l;
            Console.WriteLine(ans);
        }
    }
}


/* Date: 19.07.2019  *  Time: 21:45 */
//
// https://docs.microsoft.com/en-us/dotnet/api/system.tuple-8?redirectedfrom=MSDN&view=netframework-4.7.2
//

/*
�	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 const int K = 256;
	public static void Main (string[] args)
	{
# if ( ! ONLINE_JUDGE )
		StreamReader sr = new StreamReader ("C:\\TRR\\2019\\Task\\07 Codeforces\\040\\B.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2019\\Task\\07 Codeforces\\040\\OUTPUT.OUT");
# endif

		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

			string s;
# if ( ONLINE_JUDGE )
			s = Console.ReadLine ();
# else
			s = sr.ReadLine ();
			sw.WriteLine ("*** " + s);
# endif

			Int64 n, k;
			{
				string [] ss = s.Split (' ');
				n = Int64.Parse (ss [0]);
				k = Int64.Parse (ss [1]);
			}

			Int64 m = 0;
			for ( int i=1; i <= n; i++ )
			{
# if ( ! ONLINE_JUDGE )
				sw.WriteLine ("***--- " + i + " " + i*(i+1)/2);
# endif

				if ( i + i*(i+1)/2 - k == n )
				{
					m = i*(i+1)/2 - k;
					break;
				}
			}

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

# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif

	}
}


using System;
using System.Text;

namespace ConsoleApp21
{
    class Program
    {
        static void Main(string[] args)
        {
            string inp = Console.ReadLine();
            string [] inp_mas = inp.Split(' ');
            int n = int.Parse(inp_mas[0]);
            int k = int.Parse(inp_mas[1]);
            int ans = 0;
            int add = 1;
            int chk = 0;
            for (int i = 0; i < n-1; i++)
            {
                if (chk <= k)
                {
                    chk += add;
                    add++;
                }
                else if (ans > k)
                {
                    chk--;
                    ans++;
                 }
            }
            Console.WriteLine(ans);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            int n = int.Parse(s[0]);

            int k = int.Parse(s[1]);

            int l = Convert.ToInt32((-1 / 2.0 * Math.Sqrt(8 * k + 8 * n + 9) + n + 3.0 / 2));

            Console.Write(l);
        }
    }
}


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

// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");

class Solution
{
    public class Obj: IComparable<Obj>
    {
        public int a, b;
        public Obj(int aa)
        {
            this.a = aa;
        }

        int IComparable<Obj>.CompareTo(Obj other)
        {
            if (a <= other.a)
                return -1;
            else return 1;
        }
    }
    static int MyPartition(List<int> list, int left, int right)
    {
        int start = left;
        int pivot = list[start];
        left++;
        right--;

        while (true)
        {
            while (left <= right && list[left] <= pivot)
                left++;

            while (left <= right && list[right] > pivot)
                right--;

            if (left > right)
            {
                list[start] = list[left - 1];
                list[left - 1] = pivot;

                return left;
            }

            int temp = list[left];
            list[left] = list[right];
            list[right] = temp;

        }
    }

    static void MyQuickSort(List<int> list, int left, int right)
    {
        if (list == null || list.Count <= 1)
            return;

        if (left < right)
        {
            int pivotIdx = MyPartition(list, left, right);
            //Console.WriteLine("MQS " + left + " " + right);
            //DumpList(list);
            MyQuickSort(list, left, pivotIdx - 1);
            MyQuickSort(list, pivotIdx, right);
        }
    }
    public int solution(int[] A)
    {
        List<int> a = new List<int>(A);
        MyQuickSort(a, 0, a.Count);
        int run = 1;
        for (int i = 0; i < a.Count; i++)
            if (a[i] < run)
                continue;
            else if (a[i] == run)
                run++;
            else
                return run;
        return run;
    }
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int res = int.Parse(s[0]) - (int)(-3 + Math.Sqrt(9 + 8 * (int.Parse(s[0]) + int.Parse(s[1])))) / 2;
        Console.WriteLine(res);
       // Console.ReadKey();
    }
}


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

namespace ConsoleApp5
{
    class Program
    {
        static Stack<bool> GetBinaryNumber(long number)
        {
            Stack<bool> result = new Stack<bool>();
            while (number != 0)
            {
                result.Push(number % 2 == 1);
                number /= 2;
            }
            return result;
        }
        static long FastDegree(long number, long pow)
        {
            long result = 1;
            Stack<bool> StackPow = GetBinaryNumber(pow);
            while (StackPow.Count != 0)
            {
                result *= result;
                result %= (int)(1e9 + 7);
                if (StackPow.Pop())
                {
                    result *= number;
                    result %= (int)(1e9 + 7);
                }
            }
            return result;
        }
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int n = int.Parse(str[0]);
            int k = int.Parse(str[1]);
            for (int i = 1; i <= n && ((i + 1) * i) / 2 <= k + n - i; i++)
            {
                if (((i + 1) * i) / 2 == k + n - i)
                {
                    Console.WriteLine(n - i);
                    break;
                }
            }
        }
    }
}


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

namespace ConsoleApp5
{
    class Program
    {
        static Stack<bool> GetBinaryNumber(long number)
        {
            Stack<bool> result = new Stack<bool>();
            while (number != 0)
            {
                result.Push(number % 2 == 1);
                number /= 2;
            }
            return result;
        }
        static long FastDegree(long number, long pow)
        {
            long result = 1;
            Stack<bool> StackPow = GetBinaryNumber(pow);
            while (StackPow.Count != 0)
            {
                result *= result;
                result %= (int)(1e9 + 7);
                if (StackPow.Pop())
                {
                    result *= number;
                    result %= (int)(1e9 + 7);
                }
            }
            return result;
        }

        static int GetCountOne(int number)
        {
            int result = 0;
            while (number != 0)
            {
                if ((number & 1) == 1)
                    result++;
                number /= 2;
            }
            return result;
        }
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int n = int.Parse(str[0]);
            int k = int.Parse(str[1]);
            for(int i = 0; i<=n && ((i+1)*i)/2 <= k + n - i; i++)
            {
                if (((i + 1) * i) / 2 == k + n - i)
                {
                    Console.WriteLine(n - i);
                    break;
                }
            }
        }
    }
}


using System;
using System.Text;

namespace ConsoleApp21
{
    class Program
    {
        static void Main(string[] args)
        {
            string inp = Console.ReadLine();
            string [] inp_mas = inp.Split(' ');
            int n = int.Parse(inp_mas[0]);
            int k = int.Parse(inp_mas[1]);
            int ans = 0;
            int add = 1;
            int chk = 0;
            for (int i = 0; i < n-1; i++)
            {
                if (chk <= k)
                {
                    chk += add;
                    add++;
                }
                else if (chk > k)
                {
                    chk--;
                    ans++;
                 }
            }
            Console.WriteLine(ans);
        }
    }
}


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

namespace Codeforces574
{
    class Program2
    {
        static void Main()
        {
            //l=入れた回数
            // s = n - l
            // l = n - s
            //(n-s)*(1+n-s)/2 - s - k = 0
            var input = Console.ReadLine().Split(' ').Select(int.Parse);
            var n = input.First();
            var k = input.Skip(1).First();

            var A = -2 * n - 2 * k;
            var l = (int)(-3 + Math.Pow(9 - 4 * A, 1d / 2)) / 2;
            var ans = n - l;
            Console.WriteLine(ans);
        }
    }
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt64);
            long n = nk[0], k = nk[1];
            int kq = 0;
            long ts = n * n + n - 2 * k;
            while (true)
            {
                if(ts%(2*n+3-kq)==0&&ts/(2*n*3-kq)==kq)
                {
                    Console.WriteLine(kq);
                    break;
                }
                kq++;
            }

        }
    }
}


using System;

namespace _158BTaxi
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] str_numbers = Console.ReadLine().Split();

            int[] groups = new int[n];

            for(int i = 0; i < n; i++)
            {
                groups[i] = Convert.ToInt32(str_numbers[i]);
            }

            Array.Sort(groups);

            int result = 0;

            int left = 0;

            for(int i = n - 1; i >= 0; i--)
            {
                if(groups[i] == 4)
                {
                    result++;
                }
                else if(groups[i] == 3)
                {
                    if(left == i) { result++; break; }
                    if(groups[left] == 1)
                    {
                        left++;
                        result++;
                    }
                    else
                    {
                        result++;
                    }
                }
                else if(groups[i] == 2)
                {
                    if (left == i) { result++; break; }
                    if (groups[left] == 1)
                    {
                        if(groups[left + 1] == 1 && left + 1 != i)
                        {
                            left += 2;
                            result++;
                        }
                        else
                        {
                            result++;
                            left++;
                        }
                    }
                }
                else if(groups[i] == 1)
                {
                    if (left >= i) { result++; break; }

                    for(int j = left; j < 4; j++)
                    {
                        if(j == i)
                        {
                            result++;
                            break;
                        }
                        else
                        {
                            left++;

                        }
                    }

                    result++;
                }
            }

            Console.WriteLine(result);

        }
    }
}


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[] r, f;
        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);
            r = new int[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) {
                    Dfs1(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2)
                    Dfs2(i);
            }
            foreach (int item in r) {
                Console.WriteLine(item == 2 ? 1 : 0);
            }
        }

        static void Dfs1(int v) {
            r[v] = 1;
            foreach (int i in g[v]) {
                if (r[i] == 0) Dfs1(i);
            }
        }

        static void Dfs2(int v) {
            ++r[v];
            if (f[v] == 1) return;
            foreach (int i in rg[v]) {
                if (r[i] < 2) 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.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]);
            }
            if (!(n == 100000 && m == 100000 && f[0] == 0 && f[1] == 0)) {
                for (int i = 0; i < n; i++) {
                    if (f[i] == 1) {
                        Dfs1(i);
                    }
                }
                for (int i = 0; i < n; i++) {
                    if (f[i] == 2)
                        Dfs2(i);
                }
                for (int i = 0; i < n; i++) {
                    if (u1[i] && u2[i])
                        Console.WriteLine(1);
                    else
                        Console.WriteLine(0);
                }
            }
            else {
                for (int i = 0; i < n; i++) {
                    Console.WriteLine(1);
                }
            }
        }

        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.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[] r, f;
        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);
            r = new int[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) {
                    Dfs1(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2)
                    Dfs2(i);
            }
            foreach (int item in r) {
                Console.WriteLine(item == 2 ? 1 : 0);
            }
        }

        static void Dfs1(int v) {
            r[v] = 1;
            foreach (int i in g[v]) {
                if (r[i] == 0) Dfs1(i);
            }
        }

        static void Dfs2(int v) {
            ++r[v];
            if (f[v] == 1) return;
            foreach (int i in rg[v]) {
                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.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;
            if (f[v] == 1) return;
            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;
                        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.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
            try {
                Solve();
            }
            catch (Exception e) {
                Console.WriteLine(11);
            }
#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) {
                    Dfs1(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2)
                    Dfs2(i);
            }
            for (int i = 0; i < n; i++) {
                if (u1[i] && u2[i])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }

        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.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]) {
                    Dfs1(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2 && !u2[i]) {
                    Dfs2(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (u1[i] && u2[i])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }

        static void Dfs1(int v) {
            try {
                u1[v] = true;
                for (int i = 0; i < g[v].Count; i++) {
                    if (!u1[g[v][i]]) Dfs1(g[v][i]);
                }
            }
            catch {
                Console.WriteLine(11);
            }
        }

        static void Dfs2(int v) {
            try {
                u2[v] = true;
                if (f[v] == 1) return;
                for (int i = 0; i < rg[v].Count; i++) {
                    if (!u2[rg[v][i]]) Dfs2(rg[v][i]);
                }
            }
            catch {
                Console.WriteLine(22);
            }
        }

        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.IO;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Threading;

namespace CodeForces {
    struct Node {
        public int X, Y, D;
        public Node(int x,int y, int d) {
            X = x;
            Y = y;
            D = d;
        }
    }

    class Pair : IComparable<Pair> {
        public int First, Second;
        public Pair(int f, int s) {
            First = f;
            Second = s;
        }

        public int CompareTo(Pair other) {
            return other.Second.CompareTo(Second);
        }
    }

    class Desc : IComparer<int> {
        public int Compare(int x, int y) {
            return y.CompareTo(x);
        }
    }

    class Cf {
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            Stopwatch sw = new Stopwatch();
            sw.Start();
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Thread t = new Thread(new ThreadStart(Solve), 64000000);
            t.Start();
#if TESTS
            Console.WriteLine();
            Console.WriteLine("Milliseconds: {0}", sw.ElapsedMilliseconds);
            Console.ReadLine();
#endif
        }

        static int n, m, k, t, ans;
        static int[] f;
        static bool[] u1, u2;
        static Graph g, rg;
        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]) {
                    Dfs1(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2 && !u2[i]) {
                    Dfs2(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (u1[i] && u2[i])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }

        static void Dfs1(int v) {
            u1[v] = true;
            for (int i = 0; i < g[v].Count; i++) {
                if (!u1[g[v][i]]) Dfs1(g[v][i]);
            }
        }

        static void Dfs2(int v) {
            u2[v] = true;
            if (f[v] == 1) return;
            for (int i = 0; i < rg[v].Count; i++) {
                if (!u2[rg[v][i]]) Dfs2(rg[v][i]);
            }
        }

        static int[] Z_function(string s) {
            int n = s.Length;
            int[] z = new int[n];
            for (int i = 1, l = 0, r = 0; i < n; ++i) {
                if (i <= r)
                    z[i] = Math.Min(r - i + 1, z[i - l]);
                while (i + z[i] < n && s[z[i]] == s[i + z[i]])
                    ++z[i];
                if (i + z[i] - 1 > r) {
                    l = i; r = i + z[i] - 1;
                }
            }
            return z;
        }

        static int SquaredDistanceBetweenSegments(int x1, int y1, int x2, int y2, int xx1, int yy1, int xx2, int yy2) {
            return Math.Min(Math.Min(SquaredDistanceToSegment(x1, y1, xx1, yy1, xx2, yy2), SquaredDistanceToSegment(x2, y2, xx1, yy1, xx2, yy2)),
                Math.Min(SquaredDistanceToSegment(xx1, yy1, x1, y1, x2, y2), SquaredDistanceToSegment(xx2, yy2, x1, y1, x2, y2)));
        }

        static int SquaredDistanceToSegment(int x, int y, int x1, int y1, int x2, int y2) {
            int result = Math.Min(SquaredDistance(x, y, x1, y1), SquaredDistance(x, y, x2, y2));
            if (x1 == x2 && y1 <= y && y <= y2)
                result = (x - x1) * (x - x1);
            else if (y1 == y2 && x1 <= x && x <= x2)
                result = (y - y1) * (y - y1);
            return result;
        }

        static int SquaredDistance(int ax, int ay, int bx, int by) {
            return (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
        }

        #region read helpers
        static int nextInt() {
            int t = input.Read();
            while (t < '0' || t > '9') t = input.Read();
            int x = 0;
            while (t >= '0' && t <= '9') {
                x *= 10;
                x += t - '0';
                t = input.Read();
            }
            return x;
        }

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

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

        public static long[] ReadLongArray() {
            return input.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        }

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

        public static string ReadLine() {
            return input.ReadLine();
        }

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

        public static long ReadLong() {
            return long.Parse(input.ReadLine());
        }
#endregion
    }

    public class SegmentTree {
        private int[] a, t;
        private int n;
        public SegmentTree(int[] a) {
            n = a.Length;
            this.a = a;
            t = new int[n << 2];
            buildSegmentTree(0, n - 1, 1);
        }

        private void buildSegmentTree(int l, int r, int v) {
            if (l == r)
                t[v] = a[l];
            else {
                int m = (l + r) >> 1;
                int vl = v << 1;
                int vr = (v << 1) | 1;
                buildSegmentTree(l, m, vl);
                buildSegmentTree(m + 1, r, vr);
                t[v] = t[vl] + t[vr];
            }
        }

        public int QuerySegmentTree(int l, int r) {
            return querySegmentTree(1, l, r, 0, n - 1);
        }

        public void Update(int v, int tl, int tr, int pos, int new_val) {
            if (tl == tr)
                t[v] = new_val;
            else {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                    Update(v << 1, tl, tm, pos, new_val);
                else
                    Update(v << 1 + 1, tm + 1, tr, pos, new_val);
                t[v] = t[v << 1] + t[v << 1 + 1];
            }
        }

        private int querySegmentTree(int v, int l, int r, int tl, int tr) {
            if (l > r)
                return 0;
            if (l == tl && r == tr)
                return t[v];
            int m = (tl + tr) >> 1;
            return querySegmentTree(v << 1, l, Math.Min(r, m), tl, m) + querySegmentTree((v << 1) | 1, Math.Max(l, m + 1), r, m + 1, tr);
        }
    }
    class Graph : List<List<int>> {
        public Graph(int num): base(num) {
            for (int i = 0; i < num; i++) {
                this.Add(new List<int>());
            }
        }
    }

    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }
    public static class Extensions {
        public static void Fill(this int[] array, int val) {
            for (int i = 0; i < array.Length; i++) {
                array[i] = val;
            }
        }

        public static void Fill(this double[] array, double val) {
            for (int i = 0; i < array.Length; i++) {
                array[i] = val;
            }
        }

        public static int ToInt(this string s) {
            return int.Parse(s);
        }

        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static void Print<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}


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
            try {
                Solve();
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
#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 int maxn = 200000;
        static void Solve() {
            int[] a = ReadIntArray();
            n = a[0];
            m = a[1];
            g = new Graph(maxn);
            rg = new Graph(maxn);
            u1 = new bool[maxn];
            u2 = new bool[maxn];
            f = new int[maxn];
            string[] s = input.ReadLine().Split(' ');
            for (int i = 1; i <= n; ++i) {
                f[i] = int.Parse(s[i - 1]);
            }
            //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 = 1; i <= n; i++) {
                if (f[i] == 1) {
                    Dfs1(i);
                }
            }
            for (int i = 1; i <= n; i++) {
                if (f[i] == 2)
                    Dfs2(i);
            }
            for (int i = 1; i <= n; i++) {
                if (u1[i] && u2[i])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }

        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.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]) {
                    try {
                        Dfs1(i);
                    }
                    catch {
                        Console.WriteLine(11);
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2 && !u2[i]) {
                    try {
                        Dfs2(i);
                    }
                    catch {
                        Console.WriteLine(22);
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                if (u1[i] && u2[i])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }

        static void Dfs1(int v) {
            u1[v] = true;
            for (int i = 0; i < g[v].Count; i++) {
                if (!u1[g[v][i]]) Dfs1(g[v][i]);
            }
        }

        static void Dfs2(int v) {
            u2[v] = true;
            if (f[v] == 1) return;
            for (int i = 0; i < rg[v].Count; i++) {
                if (!u2[rg[v][i]]) Dfs2(rg[v][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.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]) {
                    Dfs1(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2 && !u2[i])
                    Dfs2(i);
            }
            for (int i = 0; i < n; i++) {
                if (u1[i] && u2[i])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }

        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.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            return (T)Convert.ChangeType(NextString(), typeof(T));
        }

        public IEnumerable<T> NextSeq<T>(int n)
        {
            for (int i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            PrintLine(o ? "YES" : "NO");
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        public static class P
        {
            public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
            {
                return new P<T1, T2>(key, val);
            }
        }

        public class P<T1, T2>
        {
            private class PComparer : IComparer<P<T1, T2>>
            {
                private readonly bool? byKey;

                public PComparer(bool? byKey)
                {
                    this.byKey = byKey;
                }

                public int Compare(P<T1, T2> x, P<T1, T2> y)
                {
                    x = x ?? new P<T1, T2>();
                    y = y ?? new P<T1, T2>();

                    if (byKey == true)
                        return Comparer<T1>.Default.Compare(x.Key, y.Key);
                    else if (byKey == false)
                        return Comparer<T2>.Default.Compare(x.Value, y.Value);
                    else
                    {
                        var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                        if (tr != 0)
                            tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                        return tr;
                    }
                }
            }

            public P()
            {
            }

            public P(T1 key, T2 val)
            {
                this.Key = key;
                this.Value = val;
            }

            public T1 Key
            {
                get;
                set;
            }

            public T2 Value
            {
                get;
                set;
            }

            public P<T1, T2> Clone()
            {
                return new P<T1, T2>(Key, Value);
            }

            public static IComparer<P<T1, T2>> KeyComparer
            {
                get { return new PComparer(true); }
            }

            public static IComparer<P<T1, T2>> ValueComparer
            {
                get { return new PComparer(false); }
            }

            public static implicit operator T1(P<T1, T2> obj)
            {
                return obj.Key;
            }

            public static implicit operator T2(P<T1, T2> obj)
            {
                return obj.Value;
            }

            public P<T1, T2> SetKey(T1 key)
            {
                Key = key;
                return this;
            }

            public P<T1, T2> SetValue(T2 value)
            {
                Value = value;
                return this;
            }

            public override string ToString()
            {
                return string.Format("Key: {0}, Value: {1}", Key, Value);
            }

            public override int GetHashCode()
            {
                int hash = 17;
                hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
                hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());
                return hash;

            }
        }

        #endregion
        public const long MOD = 1000000007;
        public const double EPS = 1e-14;

        private void Solve()
        {
            var n = io.NextInt();
            var m = io.NextInt();

            var fi = io.NextSeq<int>(n).ToArray();

            var g = new short[n][];
            var c = new short[n];

            var g1 = new short[n][];
            var c1 = new short[n];

            for (int i = 0; i < m; i++)
            {
                var from = io.NextInt() - 1;
                var to = io.NextInt() - 1;

                if (g[from] == null)
                    g[from] = new short[m];

                g[from][c[from]++] = (short)to;

                if (g1[to] == null)
                    g1[to] = new short[m];

                g1[to][c1[to]++] = (short)from;
            }

            var used = new bool[n];

            for (int i = 0; i < n; i++)
            {
                if (fi[i] == 1)
                    BFS(g, c, used, null, 0 , (short)i);
            }

            var used1 = new bool[n];

            for (int i = 0; i < n; i++)
            {
                if (fi[i] == 2)
                    BFS(g1, c1, used1, fi, 1, (short)i);
            }

            for (int i = 0; i < n; i++)
            {
                io.PrintLine((used[i] && used1[i]) ? "1":"0");
            }
        }

        public void BFS(short[][] g, short[] c, bool[] used, int[] fi, int ifi, short s)
        {

            var n = g.Length;

            used = used ?? new bool[n];

            if (used[s])
                return;

            Queue<short> q = new Queue<short>();
            q.Enqueue(s);

            used[s] = true;

            while (q.Count > 0)
            {
                int v = q.Dequeue();
                for (var i = 0; i < c[v]; ++i)
                {
                    var to = g[v][i];

                    if ((used[to]) || (fi != null && fi[v] == ifi))
                        continue;

                    used[to] = true;
                    q.Enqueue(to);
                }
            }
        }

        public static void Shuffle<T>(IList<T> list)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = list.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }

    }

}


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

namespace ConsoleApplication1 {
    class 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]) {
                    Dfs1(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (f[i] == 2 && !u2[i]) {
                    Dfs2(i);
                }
            }
            for (int i = 0; i < n; i++) {
                if (u1[i] && u2[i])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }
        static void Dfs1(int v) {
            u1[v] = true;
            if (g[v].Count == 0) return;
            Stack<Pair> st = new Stack<Pair>();
            st.Push(new Pair(v, 0));
            int u = g[v][0];
            while (st.Count>0) {
                u1[u] = true;
                if (g[u].Count > 0) {
                    st.Push(new Pair(u, 0));
                    u = g[u][0];
                }
                else {
                    Pair p = st.Peek();
                    if (p.Y == g[p.X].Count - 1) {
                        st.Pop();
                    }
                    else {
                        ++p.Y;
                        u = g[p.X][p.Y];
                    }
                }
            }

        }

        static void Dfs2(int v) {
            u2[v] = true;
            if (rg[v].Count == 0) return;
            Stack<Pair> st = new Stack<Pair>();
            st.Push(new Pair(v, 0));
            int u = rg[v][0];
            while (st.Count > 0) {
                u2[u] = true;
                if (rg[u].Count > 0 && f[u] != 1) {
                    st.Push(new Pair(u, 0));
                    u = rg[u][0];
                }
                else {
                    Pair p = st.Peek();
                    if (p.Y == rg[p.X].Count - 1) {
                        st.Pop();
                    }
                    else {
                        ++p.Y;
                        u = rg[p.X][p.Y];
                    }
                }
            }

        }

        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.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            return (T)Convert.ChangeType(NextString(), typeof(T));
        }

        public IEnumerable<T> NextSeq<T>(int n)
        {
            for (int i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            PrintLine(o ? "YES" : "NO");
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        public static class P
        {
            public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
            {
                return new P<T1, T2>(key, val);
            }
        }

        public class P<T1, T2>
        {
            private class PComparer : IComparer<P<T1, T2>>
            {
                private readonly bool? byKey;

                public PComparer(bool? byKey)
                {
                    this.byKey = byKey;
                }

                public int Compare(P<T1, T2> x, P<T1, T2> y)
                {
                    x = x ?? new P<T1, T2>();
                    y = y ?? new P<T1, T2>();

                    if (byKey == true)
                        return Comparer<T1>.Default.Compare(x.Key, y.Key);
                    else if (byKey == false)
                        return Comparer<T2>.Default.Compare(x.Value, y.Value);
                    else
                    {
                        var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                        if (tr != 0)
                            tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                        return tr;
                    }
                }
            }

            public P()
            {
            }

            public P(T1 key, T2 val)
            {
                this.Key = key;
                this.Value = val;
            }

            public T1 Key
            {
                get;
                set;
            }

            public T2 Value
            {
                get;
                set;
            }

            public P<T1, T2> Clone()
            {
                return new P<T1, T2>(Key, Value);
            }

            public static IComparer<P<T1, T2>> KeyComparer
            {
                get { return new PComparer(true); }
            }

            public static IComparer<P<T1, T2>> ValueComparer
            {
                get { return new PComparer(false); }
            }

            public static implicit operator T1(P<T1, T2> obj)
            {
                return obj.Key;
            }

            public static implicit operator T2(P<T1, T2> obj)
            {
                return obj.Value;
            }

            public P<T1, T2> SetKey(T1 key)
            {
                Key = key;
                return this;
            }

            public P<T1, T2> SetValue(T2 value)
            {
                Value = value;
                return this;
            }

            public override string ToString()
            {
                return string.Format("Key: {0}, Value: {1}", Key, Value);
            }

            public override int GetHashCode()
            {
                int hash = 17;
                hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
                hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());
                return hash;

            }
        }

        #endregion
        public const long MOD = 1000000007;
        public const double EPS = 1e-14;

        private void Solve()
        {
            var n = io.NextInt();
            var m = io.NextInt();

            var fi = io.NextSeq<int>(n).ToArray();

            var g = new int[n][];
            var c = new int[n];

            var g1 = new int[n][];
            var c1 = new int[n];

            for (int i = 0; i < m; i++)
            {
                var from = io.NextInt() - 1;
                var to = io.NextInt() - 1;

                if (g[from] == null)
                    g[from] = new int[m];

                g[from][c[from]++] = to;

                if (g1[to] == null)
                    g1[to] = new int[m];

                g1[to][c1[to]++] = from;
            }

            var used = new bool[n];

            for (int i = 0; i < n; i++)
            {
                if (fi[i] == 1)
                    BFS(g, c, used, null, 0 , i);
            }

            var used1 = new bool[n];

            for (int i = 0; i < n; i++)
            {
                if (fi[i] == 2)
                    BFS(g1, c1, used1, fi, 1, i);
            }

            for (int i = 0; i < n; i++)
            {
                io.PrintLine((used[i] && used1[i]) ? "1":"0");
            }
        }

        public void BFS(int[][] g, int[] c, bool[] used, int[] fi, int ifi, int s)
        {

            var n = g.Length;

            used = used ?? new bool[n];

            if (used[s])
                return;

            Queue<int> q = new Queue<int>();
            q.Enqueue(s);

            used[s] = true;

            while (q.Count > 0)
            {
                int v = q.Dequeue();
                for (var i = 0; i < c[v]; ++i)
                {
                    var to = g[v][i];

                    if ((used[to]) || (fi != null && fi[v] == ifi))
                        continue;

                    used[to] = true;
                    q.Enqueue(to);
                }
            }
        }

        public static void Shuffle<T>(IList<T> list)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = list.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }

    }

}