using System;

static class Program
{
    static void Main()
    {
        var numbers = GetAllNumbers(Console.ReadLine());
        var firstNumber = int.Parse(numbers[0].ToString());
        var secondNumber = int.Parse(numbers[1].ToString());

        if(firstNumber > 1 && secondNumber < Math.Pow(10, 9) && Math.Min(firstNumber, secondNumber) <= 12)
        {
            var firstFact = GetFact(firstNumber);
            var secondFact = GetFact(secondNumber);

            var dilnik = GetDilnik(firstFact, secondFact);

            Console.WriteLine(dilnik);
        }

    }

    static int GetDilnik(int a, int b)
    {
        var lowerNumber = a > b ? b : a;

        if(a % lowerNumber == 0 && b%lowerNumber == 0)
        {
            return lowerNumber;
        }

        for(int i = 1; i <lowerNumber; i++)
        {
            var nextIteration = lowerNumber - 1;
            if(a%nextIteration == 0 && b%nextIteration == 0)
            {
                return nextIteration;
            }
        }
        return 1;
    }

    static int GetFact(int input)
    {
        if(input == 0)
        {
            return 0;
        }
        else if(input == 1)
        {
            return input;
        }
        else
        {
            return input * GetFact(input-1);
        }
    }

    static int[] GetAllNumbers(string input)
    {
        var result = new int[2];
        var resultIndex = 0;
        var index = 0;
        string currentSymbol = " ";

        while( index < input.Length)
        {
            var nextSymbol = input[index].ToString();
            if(nextSymbol == " ")
            {
                result[resultIndex] = int.Parse(currentSymbol);
                resultIndex++;
                currentSymbol = nextSymbol;
            }
            else if(index ==  input.Length -1)
            {
                if(nextSymbol != " ")
                {
                    currentSymbol += nextSymbol;
                }
                result[resultIndex] = int.Parse(currentSymbol);
            }
            else
            {
                currentSymbol += nextSymbol;
            }
            index++;
        }

        return result;
    }
}


using System;
using System.Linq;
namespace Example
{
    class Program
    {
        static void Main()
        {
            string[] Str = Console.ReadLine().Split(' ');
            int a = int.Parse(Str[0]);
            int b = int.Parse(Str[1]);
            Console.WriteLine(NOD(Factorial(a),Factorial(b)));
        }

        static int Factorial(int x)
        {
            if (x == 0) return 1;
            else return x * Factorial(x - 1);
        }

        static int NOD(int a, int b)
        {
            int nod = 0;
            for (int i = 1; i < (a * b + 1); i++)
            {
                if (a % i == 0 && b % i == 0)
                {
                    nod = i;
                }
            }
            return nod;
        }
    }
}


using System;

class a
{
    static void Main()
    {
        var a = Array.ConvertAll(Console.ReadLine().Split(), ulong.Parse);
        Console.WriteLine(GCD(Fac(a[0]),Fac(a[1])));
    }
    static ulong Fac(ulong n)
    {
        ulong r = n;
        for (ulong i = 1; i < n; i++)
        {
            r *= n - i;
        }
        return r;
    }
    private static ulong GCD(ulong a, ulong b)
    {
        while (a != 0 && b != 0)
        {
            if (a > b)
                a %= b;
            else
                b %= a;
        }
        return a == 0 ? b : a;
    }
}


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

public class Program
{
	public static void Main()
	{
		var arr=Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int a=1, b=1;

		for(int i=1; i<=arr[0]; i++)
			a*=i;
		for(int i=1; i<=arr[1]; i++)
			b*=i;
		while (a!=b)
		{
			if (a>b)
				a = a - b;

			if (b > a)
				b = b- a;
		}
		Console.WriteLine(a);
	}
}


using System;

class Program
{
    static void Main()
    {
        int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int a = arr[0];
        int b = arr[1];

        Console.WriteLine(Gcd(Fac(a), Fac(b)));
    }

    static long Fac(int n)
    {
        if (n == 0)
            return 1;
        long result = 1;
        for (int i = 2; i <= n; i++)
            result *= i;
        return result;
    }

    static long Gcd(long a, long b)
    {
        while (b != 0)
        {
            long t = b;
            b = a % b;
            a = t;
        }

        return a;
    }
}


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

namespace CodeForces
{
    class A
    {
        static void Main(string[] args)
        {
           string[] token = Console.ReadLine().Split();
           int A = int.Parse(token[0]);
           int B = int.Parse(token[1]);

           int fA = 1,fB = 1;
           for(int i=1;i<A+1;i++)
           {
              fA *= i;
           }
           for(int i=1;i<B+1;i++)
           {
              fB *= i;
           }

           int minNum = Math.Min(fA,fB);
           int maxNum = Math.Max(fA,fB);

           Console.WriteLine(GCD(maxNum,minNum));
        }

        static int GCD(int max,int min)
        {
           int dividend = max;
           int divisor = min;

           int rem = int.MaxValue;
           int ans = 0;
          while(true)
          {
             rem = dividend%divisor;
             if(rem==0)
             {
                ans = divisor;
                break;
             }
             divisor = dividend;
             rem = divisor;
          }
           return ans;
        }
    }
}


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

namespace Factorial
{
    class Program
    {
        public long Gcd(long a, long b) { if (b == 0) return a; return Gcd(b, a % b); }
        public long Factorial(long a) { long product = 1; for (int i = 1; i <= a; i++) product *= i; return product; }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long[] a = new long[s.Length]; for (int i = 0; i < a.Length; i++) a[i] = Convert.ToInt64(s[i]);
            Program p = new Program();
            Console.WriteLine(p.Gcd(p.Factorial(a[0]), p.Factorial(a[1])));
        }
    }
}


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

namespace Factorial
{
    class Program
    {
        public long Factorial(long a) { long product = 1; for (int i = 1; i <= a; i++) product *= i; return product; }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long[] a = new long[s.Length]; for (int i = 0; i < a.Length; i++) a[i] = Convert.ToInt64(s[i]);
            Program p = new Program();
            long t = Math.Min(a, b);
            Console.WriteLine(p.Factorial(t));
        }
    }
}


using System;
class Demo
{
    static long Fact(int i)
    {
        if (i == 1 || i == 0)
            return 1;
        return i * Fact(i - 1);
    }
    static long NOD(long a, long b)
    {
        do
        {
          a = Math.Max(a,b)%Math.Min(a,b);
        } while (a!=0);
        return b;
    }
    static void Main()
    {
        int[] args = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(NOD(Fact(args[0]), Fact(args[1])));
    }
}


using System;

namespace A._I_m_bored_with_life
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] data = Console.ReadLine().Split(' ');
            long num1 = Convert.ToInt64(data[0]);
            long num2 = Convert.ToInt64(data[1]);
            if (num1 > num2)
            {
                var temp = num1;
                num1 = num2;
                num2 = temp;
            }
            long min = num1;

            for (long i = num1 - 1; i > 1; i--)
            {
                num1 = num1 * i;
            }

            for (long i = num2 - 1; i > 1; i--)
            {
                num2 = num2 * i;
            }

            for (long i = 1; i < min; i++)
            {
                if (num2 % (num1 / i) == 0)
                {
                    Console.WriteLine((num1 / i));
                    return;
                }
            }
        }
    }
}


using System;
class MyBuild
{
    static void Main()
    {
        string input = Console.ReadLine();
        string[] strnum = input.Split(' ');
        int[] numsin = Array.ConvertAll(strnum, int.Parse);

        int milliliters = numsin[1] * numsin[2];
        int totalslices = numsin[3] * numsin[4];
        int salt = numsin[5];

        int toastchecker = 3;
        int toastcounter = -1;

        while (toastchecker ==3)
        {
            toastchecker = 0;

            milliliters -= numsin[0] * numsin[6];
            totalslices -= numsin[0];
            salt -= numsin[0] * numsin[7];

            if (milliliters >= 0)
            {
                toastchecker++;
            }
            if (totalslices > 0)
            {
                toastchecker++;
            }
            if (salt > 0)
            {
                toastchecker++;
            }

            toastcounter++;
        }

        Console.WriteLine(toastcounter);

    }
}


using System; using System.Linq;

class Program {
  static void Main() {
    var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var n = s[0]; var k = s[1]; var l = s[2]; var c = s[3]; var d = s[4];
    var p = s[5]; var nl = s[6]; var np = s[7];
    Console.WriteLine(new [] {}.Min(k*l/nl, c*d, p/np) / n);
  }
}


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

namespace App2 {
    class Program
    {
        Regex regex;
        void Solve()
        {
            //StreamReader textFile = new StreamReader("c:\\in.txt");

            regex = new Regex("[^\\d\\-]{1,}");

            //string []s = regex.Split("0, 9, 12, 232, 5  3 -1");
            string[] s = regex.Split(Console.In.ReadToEnd());
            //string[] s = regex.Split(textFile.ReadToEnd());

            int L = Int32.Parse(s[0]);
            int R = Int32.Parse(s[1]);

            if (len(L) < len(R))
            {
                L = (int)Math.Round(Math.Pow(10, len(R)-1));
            }
            int ll = len(L);
            int powN = (int)Math.Round(Math.Pow(10, ll - 1));
            int nines = (int)Math.Round(Math.Pow(10, ll) - 1);

            Int64 answer = 1L * L * (nines - L);
            answer = Math.Max(answer, 1L * R * (nines - R));
            if (L <= 5 * powN && 5 * powN <= R)
            {
                answer = Math.Max(answer, 5 * powN * (nines - 5 * powN));
            }

            Console.WriteLine(answer);
        }

        int len(int n)
        {
            int res = 0;
            while (n > 0)
            {
                ++res;
                n /= 10;
            }
            return res;
        }

        static void Main()
        {
            new Program().Solve();
        }
    }
}


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

class Solver
{
    public void Solve()
    {
        /*
        long max = 0;
        for (int i = 0; ; i++)
        {
            long a = _search(i, i);
            if (a > max)
            {
                Debug.WriteLine(i + "\t" + a+"\tmax");
                max = a;
            }
            else
                Debug.WriteLine(i + "\t" + a);

        }
        */

        var ss = CF.ReadLine().Split(' ');
        int l = int.Parse(ss[0]);
        int r = int.Parse(ss[1]);

        int d = _d(r);
        int dmax = 0;
        {
            for (int i = 0; i < d ; i++)
            {
                dmax *= 10;
                if( i==0)
                    dmax += 4;
                else
                    dmax += 9;
            }
        }

        int n;
        if (r < dmax)
            n = r;
        else if (l > dmax)
            n = l;
        else
            n = dmax;

        CF.WriteLine(_search(n, n));
    }

    int _d(int n)
    {
        int d = 0;
        {
            int tmp = n;
            for (; ; )
            {
                if (tmp == 0)
                    break;
                d += 1;
                tmp /= 10;
            }
        }
        return d;
    }

    long _search(int l,int r)
    {
        long max = 0;
        for (int i = l; i <= r; i++)
        {
            int tmp = i;
            Stack<int> ds = new Stack<int>();
            for (; ; )
            {
                if (tmp == 0)
                    break;
                ds.Push(tmp % 10);
                tmp/= 10;
            }

            int o=0;
            foreach (var d in ds)
            {
                o *= 10;
                o += (9-d);
            }

            long p = (long)o * i;
            max = Math.Max(p, max);
        }
        return max;
    }

    //  test
    static Utils CF = new Utils(new[]{
@"
1 999
",

@"
500000000 999999999
",
@"
3 7
",
 @"
1 1
",
 @"
8 10
"

    });
    #region test

    static void Main(string[] args)
    {
#if DEBUG
        for (int t=0;t<CF.TestCount;t++ )
        {
            CF.Test(t);
            new Solver().Solve();
        }
#else
        new Solver().Solve();
#endif
    }

    class Utils
    {
        public void Test(int t)
        {
            _lines = new List<string>();
            string[] ss = _test_input[t].Replace("\n", "").Split('\r');
            for (int i = 0; i < ss.Length; i++)
            {
                if (
                    (i == 0 || i == ss.Length - 1) &&
                    ss[i].Length == 0
                    )
                    continue;

                _lines.Add(ss[i]);
            }
        }

        public int TestCount
        {
            get
            {
                return _test_input.Length;
            }
        }

        public string ReadLine()
        {
#if DEBUG
            string s = null;
            if (_lines.Count > 0)
            {
                s = _lines[0];
                _lines.RemoveAt(0);
            }
            return s;

#else
            //return _sr.ReadLine();
        return Console.In.ReadLine();
#endif
        }

        public void WriteLine(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.WriteLine(o);
#else
            //_sw.WriteLine(o);
        Console.WriteLine(o);
#endif
        }

        public void Write(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.Write(o);
#else
                //_sw.Write(o);
        Console.Write(o);
#endif
        }

        string[] _test_input;

        List<string> _lines;

#if DEBUG
        public Utils(string[] test_input)
        {
            _test_input = test_input;
        }
#else

        public Utils(string[] dummy)
        {
            //_sr = new System.IO.StreamReader("input.txt");
            //_sw = new System.IO.StreamWriter("output.txt");
        }
#endif

    }

    #endregion
}


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

namespace _86A
{
    class Program
    {
        static void Main(string[] args)
        {
            int l = 0, r = 0;
            string input = Console.ReadLine();
            l = Convert.ToInt32(input.Split(' ')[0]);
            r = Convert.ToInt32(input.Split(' ')[1]);

            string sl = l.ToString();
            string sr = r.ToString();

            int num = 0;

            if (sr.Length > sl.Length)
            {
                if (Convert.ToInt16(sr[0]) - 48 >= 5)
                {
                    string biggest = "5";
                    for (int i = 0; i < sr.Length - 1; i++)
                    {
                        biggest += "0";
                    }
                    num = Convert.ToInt32(biggest);
                }
                else
                {
                    num = r;
                }
            }
            else if (sr.Length == sl.Length)
            {
                if (r == l)
                {
                    num = r;
                }

                else if (Convert.ToInt16(sr[0]) - 48 >= 5 && Convert.ToInt16(sl[0]) - 48 >= 5)
                {
                    num = l;
                }
                else if (Convert.ToInt16(sr[0]) - 48 <= 4 && Convert.ToInt16(sl[0]) - 48 <= 4)
                {
                    num = r;
                }
                else
                {
                    string biggest = "5";
                    for (int i = 0; i < sr.Length-1; i++)
                    {
                        biggest += "0";
                    }
                    num = Convert.ToInt32(biggest);

                }

            }

            Console.WriteLine(refl(num) * num);
            Console.ReadLine();

        }

        static public int refl(int num)
        {
            string sr = num.ToString();
            string nine = "";
            for (int i = 0; i < sr.Length; i++)
            {
                nine += "9";
            }

            return( Convert.ToInt32(nine) - num);
        }
    }
}


using System;

class Program
{
    static void Main()
    {
            int number = int.Parse(Console.ReadLine());
            if (number > 2 && number % 2 == 0)
        {
            Console.WriteLine("YES");
        }
            else
        {
            Console.WriteLine("NO");
        }

    }


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

namespace CFtest
{
    class Program
    {
        static void Main(string[] args)
        {
            int w;
            if (1 <= w && w <= 100 && w % 2 == 0)
            {
                Console.WriteLine("YES");
            }
            else { Console.WriteLine("NO"); }
        }
    }
}


class Program
    {
        static void Main(string[] args)
        {
            int numberOfChars = Convert.ToInt32(Console.ReadLine());
            string inputString = Console.ReadLine();
            int toRemove = 0;

            Console.WriteLine(inputString);
            for(int i = 0; i < inputString.Length-2; i++)
            {
                string currentString = inputString.Substring(i, 3);
                Console.WriteLine(currentString);
                if(currentString.Contains("xxx"))
                {
                    toRemove++;
                }
            }
            Console.WriteLine(toRemove);
        }
    }


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[n] == 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.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;
            }
        }

    }

}


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

namespace Codeforces_249_2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] d = Console.ReadLine().Split(' ');
            HashSet<string> S = new HashSet<string>();
            string max = d[0];
            S.Add(max);
            for (int k = int.Parse(d[1]); 0 < k; --k) {
                HashSet<string> T = new HashSet<string>(S);
                foreach (string s in T)
                    for (int i = s.Length-1; 0 < i; --i)
                        if (s[i - 1] < s[i]) {
                            string t = s.Substring(0, i - 1) + s[i] + s[i - 1] + s.Substring(i + 1);
                            if (!S.Contains(t)) {
                                S.Add(t);
                                if (string.Compare(max, t) < 0) max = t;
                            }
                        }
            }
            Console.WriteLine(max);
        }
    }
}


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

namespace Codeforces_249_2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] S = Console.ReadLine().Split(' ');
            long max = long.Parse(S[0]);
            SortedList<long, byte> ALL = new SortedList<long, byte>();
            List<long> CUR = new List<long>();
            ALL.Add(max, 0);
            CUR.Add(max);
            for (int k = int.Parse(S[1]); 0 < k; --k) {
                List<long> NEW = new List<long>();
                foreach (long L in CUR)
                    for (long d = 1; d < L; d *= 10) {
                        long c1 = L / d;
                        long c2 = (c1 / 10) % 10;
                        c1 %= 10;
                        if (c2 < c1) {
                            long T = L + d * 9 * (c1 - c2);
                            if (!ALL.ContainsKey(T)) {
                                ALL.Add(T, 0);
                                NEW.Add(T);
                                if (max < t) max = T;
                            }
                        }
                CUR = NEW;
            }
            Console.WriteLine(max);
        }
    }
}


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

namespace Codeforces_249_2
{
    class Program
    {
        static string solve(string s, int k)
        {
            if (k < 1) return s;
            int m = 0;
            for (int i = 1; i < s.Length && i <= k; ++i)
                if (s[m] < s[i]) m = i;
            return s[m] + solve(s.Substring(0, m) + s.Substring(m + 1), k - m);
        }
        static void Main(string[] args)
        {
            string[] S = Console.ReadLine().Split(' ');
            Console.WriteLine( solve( S[0], int.Parse(S[1]) ) );
        }
    }
}


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

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

            #region Ввод
lol:
            string input = Console.ReadLine();

            var data = input.Split(' ');

            int[] numbers = new int[data[0].Length];

            for (int index = 0; index < data[0].Length; index++)
            {
                numbers[index] = (int) Char.GetNumericValue(data[0][index]);
            }

            int k = Convert.ToInt32(data[1]);

            #endregion

            Tuple<int, int> pos;
            int m = 0;
            int m2 = 0;
            while (k > 0)
            {
                ////if (k+1-m2 <=0) break;

                //if (k >= numbers.Length)
                //{
                //    m = numbers.ToList().IndexOf(numbers.Max());

                //    if (m == 0)
                //    {
                //        if (fi)
                //        m2++;
                //        continue;
                //    }

                //    numbers = DvigLeft(numbers, m + m2, m2);

                //    k -= m;
                //}
                //else
                //{
                    pos = FindToChange(numbers, k);

                    if (pos.Item2 - pos.Item1 == 0) break;

                    numbers = DvigLeft(numbers, pos.Item2, pos.Item1);

                    k -= pos.Item2 - pos.Item1;
                    //m = numbers.ToList().GetRange(m2, k+1-m2).IndexOf(numbers.ToList().GetRange(m2, k+1-m2).Max());
                //}
            }

            #region Вывод

            string res = numbers.Aggregate("", (current, number) => current + number);

            Console.WriteLine(res);
            //Console.ReadKey();
            goto lol;

            #endregion

        }

        private static int FindToChange(int[] numbers)
        {
            for (int i = 1; i < numbers.Length; i++)
            {
                if (numbers[i - 1] < numbers[i]) return i;
            }
            return 0;
        }

        private static Tuple<int, int> FindToChange(int[] numbers, int k)
        {
            int maxindex = 0;
            int maxvalue = 0;
            int minindex = 0;

            for (int i = 0; i < numbers.Length; i++)
            {
                int indx = k+1 + minindex;
                if (indx >= numbers.Length)
                    indx = numbers.Length;

                    for (int j = minindex; j < indx; j++)
                    {
                        if (maxvalue < numbers[j])
                        {
                            maxvalue = numbers[j];
                            maxindex = j;
                        }
                    }

                if (maxindex != minindex && maxindex> minindex)
                    return new Tuple<int, int>(minindex, maxindex);

                minindex++;
            }

            return new Tuple<int, int>(0,0);
        }

        static int[] DvigLeft(int[] old, int oldpos, int newpos)
        {
            int[] res = (int[]) old.Clone();

            res[newpos] = old[oldpos];

            for (int i = newpos; i < oldpos; i++)
            {
                res[i+1] = old[i];
            }

            return res;
        }
    }
}


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

namespace Compote
{
    class Program
    {
        static void Main(string[] args)
        {
            int l = Int32.Parse(Console.ReadLine());
            int a = Int32.Parse(Console.ReadLine());
            int p = Int32.Parse(Console.ReadLine());
            int min = 0;
            if (a >= 2 * l && p >= 4 * l)
                Console.WriteLine(a + 2 * a + 4 * a);
            else
            {
                min = Math.Min(a / 2, p / 4);
                Console.WriteLine(min + min * 2 + min * 4);
            }
            Console.ReadLine();
        }
    }
}


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

namespace Graph
{

    class Program
    {
        static void Main(string[] args)
        {
            int lemonse= int.Parse(Console.ReadLine());
            int apple = int.Parse(Console.ReadLine());
            int pears = int.Parse(Console.ReadLine());
            int maxResult = 0;
            while(apple >= 2 && pears >= 4)
            {
                maxResult += 7;
                lemonse--;
                apple -= 2;
                pears -= 4;
            }
            Console.WriteLine(maxResult);

        }
    }
}


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

namespace problem1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            int y = int.Parse(Console.ReadLine());
            int z = int.Parse(Console.ReadLine());
            int a = 0, b = 0;
            for (int i = 0; i < 100; i++)
            {
                a = x * 2;
                if (a > y)
                { x--; ; }
                else
                {
                    b = a * 2;
                    if (b > z)
                        x--;

                }
            }
            Console.WriteLine(a + b + x);
            Console.ReadLine();
        }
    }
}


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

namespace ProjectContest
{
    class Test
    {
        static void Main()
        {
            int kq = Convert.ToInt32(Console.ReadLine());
            kq = Math.Min(kq, Convert.ToInt32(Console.ReadLine()) / 2);
            kq = Math.Min(kq, Convert.ToInt32(Console.ReadLine()));
            Console.WriteLine(kq * 7);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Text;

namespace Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = new List<int>(System.Console.ReadLine().Split(' ').Select(int.Parse));
            var a = arr[0];
            var b = arr[1];
            var c = arr[2];
            var l = arr[3];

            var ans = (l + 1)*(l + 2)*(l + 3)/6;
            for (int i = 0; i <= l; ++i)
            {
                ans -= Fun(a + i, b, c, l - i);
                ans -= Fun(b + i, a, c, l - i);
                ans -= Fun(c + i, b, a, l - i);
            }
            System.Console.Write(ans);
            //System.Console.ReadLine();
        }

        static int Fun(int a, int b, int c, int x)
        {
            if (a < b + c)
                return 0;
            var min = Math.Min(a - b - c, x);
            return (min + 1)*(min + 2)/2;
        }
    }
}


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

namespace GoogleCodeJam2021
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] a = Console.ReadLine().ToCharArray();
            bool b = true;
            if (a.Length > 2)
            {
                if (test(a[0]) + test(a[1]) != test(a[2])) b = false;
            }

            if (b) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }

        static int test(char a)
        {
            return (int)a - 65;
        }
    }
}