Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used!

Vasya's life goes in states of a program. In each state, Vasya can either be used (for example, to calculate the value of another variable), or be assigned a value, or ignored. Between some states are directed (oriented) transitions.

A path is a sequence of states v1, v2, ..., vx, where for any 1 ≤ i < x exists a transition from vi to vi + 1.

Vasya's value in state v is interesting to the world, if exists path p1, p2, ..., pk such, that pi = v for some i (1 ≤ i ≤ k), in state p1 Vasya gets assigned a value, in state pk Vasya is used and there is no state pi (except for p1) where Vasya gets assigned a value.

Help Vasya, find the states in which Vasya's value is interesting to the world.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the numbers of states and transitions, correspondingly.

The second line contains space-separated n integers f1, f2, ..., fn (0 ≤ fi ≤ 2), fi described actions performed upon Vasya in state i: 0 represents ignoring, 1 — assigning a value, 2 — using.

Next m lines contain space-separated pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), each pair represents the transition from the state number ai to the state number bi. Between two states can be any number of transitions.

Output

Print n integers r1, r2, ..., rn, separated by spaces or new lines. Number ri should equal 1, if Vasya's value in state i is interesting to the world and otherwise, it should equal 0. The states are numbered from 1 to n in the order, in which they are described in the input.

Examples

Input

4 3
1 0 0 2
1 2
2 3
3 4


Output

1
1
1
1


Input

3 1
1 0 2
1 3


Output

1
0
1


Input

3 1
2 0 1
1 3


Output

0
0
0

Note

In the first sample the program states can be used to make the only path in which the value of Vasya interests the world, 1 <image> 2 <image> 3 <image> 4; it includes all the states, so in all of them Vasya's value is interesting to the world.

The second sample the only path in which Vasya's value is interesting to the world is , — 1 <image> 3; state 2 is not included there.

In the third sample we cannot make from the states any path in which the value of Vasya would be interesting to the world, so the value of Vasya is never interesting to the world.
import java.io.*;
import java.util.*;

public class Main {
//	static Scanner in; static int next() throws Exception {return in.nextInt();};
	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
//	static BufferedReader in;
	static PrintWriter out;

	public static void main(String[] args) throws Exception {
//		in = new Scanner(System.in);
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		int n = next();
		int m = next();

		int[] f = new int[n];
		for (int i = 0; i < n; i++) f[i] = next();

		ArrayList<Integer>[] g = new ArrayList[n];
		for (int i = 0; i < n; i++) g[i] = new ArrayList<Integer>();
		ArrayList<Integer>[] r = new ArrayList[n];
		for (int i = 0; i < n; i++) r[i] = new ArrayList<Integer>();

		for (int i = 0; i < m; i++) {
			int a = next() - 1;
			int b = next() - 1;

			g[a].add(b);
			r[b].add(a);
		}

/*		for (int i = 0; i < n; i++) {
			out.print(i + ": ");
			for (int w : g[i]) out.print(w + " ");
			out.println();
		}
		for (int i = 0; i < n; i++) {
			out.print(i + ": ");
			for (int w : r[i]) out.print(w + " ");
			out.println();
		}
*/
		int[] x = new int[n];

		int[] v = new int[n];
		int ind = 0;
		boolean[] take = new boolean[n];
		for (int i = 0; i < n; i++) if (f[i] == 1) {
			take[i] = true;
			v[ind++] = i;
		}

		for (int i = 0; i < ind; i++) for (int w : g[v[i]]) if (!take[w]) {
			take[w] = true;
			v[ind++] = w;
		}

		for (int i = 0; i < ind; i++) x[v[i]]++;

/*		for (int i = 0; i < ind; i++) out.print(v[i] + " ");
		out.println();
*/
		ind = 0;
		Arrays.fill(take, false);

		for (int i = 0; i < n; i++) if (f[i] == 2) {
			take[i] = true;
			v[ind++] = i;
		}

/*		for (int i = 0; i < ind; i++) out.print(v[i] + " ");
		out.println();
*/
		for (int i = 0; i < ind; i++) if (f[v[i]] != 1) for (int w : r[v[i]]) if (!take[w]) {
			take[w] = true;
			v[ind++] = w;
		}

/*		for (int i = 0; i < ind; i++) out.print(v[i] + " ");
		out.println();
*/
		for (int i = 0; i < ind; i++) x[v[i]]++;

		for (int i= 0; i < n; i++) out.println(x[i]/2);



		out.close();
	}
}