#include <bits/stdc++.h>
using namespace std;
int n, m, x[100005], f[2][100005], v[2][100005], o[2][100005], q[100005], l, h;
bool u[2][100005];
void bfs(int r) {
  l = h = 0;
  for (int i = 1; i <= n; i++)
    if (x[i] == r + 1) q[h++] = i, u[r][i] = 1;
  for (; l < h; l++) {
    for (int i = f[r][q[l]]; i; i = o[r][i])
      if (!u[r][v[r][i]]) {
        u[r][v[r][i]] = 1;
        if (x[v[r][i]] != 1) q[h++] = v[r][i];
      }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v[1][i] = a;
    o[1][i] = f[1][b];
    f[1][b] = i;
    v[0][i] = b;
    o[0][i] = f[0][a];
    f[0][a] = i;
  }
  for (int i = 0; i <= 1; i++) bfs(i);
  for (int i = 1; i <= n; i++) puts(u[0][i] && u[1][i] ? "1" : "0");
  scanf("\n");
}
