#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int pre1[N], nxt1[N], to1[N], cnt1, pre2[N], nxt2[N], to2[N], cnt2, n, m, v1[N],
    v2[N], s[N], vis[N];
void makeedge(int x, int y) {
  to1[cnt1] = y;
  nxt1[cnt1] = pre1[x];
  pre1[x] = cnt1++;
  to2[cnt2] = x;
  nxt2[cnt2] = pre2[y];
  pre2[y] = cnt2++;
}
void dfs1(int x) {
  v1[x] = 1;
  for (int it = pre1[x]; it != -1; it = nxt1[it]) {
    int y = to1[it];
    if (vis[it] || s[y] == 1 || v1[y]) continue;
    vis[it] = 1;
    dfs1(y);
    vis[it] = 0;
  }
}
void dfs2(int x) {
  v2[x] = 1;
  if (s[x] == 1) return;
  for (int it = pre2[x]; it != -1; it = nxt2[it]) {
    int y = to2[it];
    if (vis[it] || v2[y]) continue;
    vis[it] = 1;
    dfs2(y);
    vis[it] = 0;
  }
}
int main() {
  memset(pre1, -1, sizeof(pre1));
  memset(pre2, -1, sizeof(pre2));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    makeedge(x, y);
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == 1) dfs1(i);
    if (s[i] == 2) dfs2(i);
  }
  for (int i = 1; i <= n; i++) printf("%d\n", v1[i] & v2[i]);
  return 0;
}
