#include <bits/stdc++.h>
using namespace std;
vector<int> G[(int)(1e5 + 500)], RG[(int)(1e5 + 500)];
int f1[(int)(1e5 + 500)], f2[(int)(1e5 + 500)], vis[(int)(1e5 + 500)],
    val[(int)(1e5 + 500)];
void dfs1(int x) {
  vis[x] = 1;
  f1[x] = 1;
  for (int i = 0; i < G[x].size(); i++) {
    int to = G[x][i];
    if (!vis[to] && (val[to] == 0 || val[to] == 2)) dfs1(to);
  }
}
void dfs2(int x) {
  vis[x] = 1;
  f2[x] = 1;
  if (val[x] == 1) return;
  for (int i = 0; i < RG[x].size(); i++) {
    int to = RG[x][i];
    if (!vis[to]) {
      dfs2(to);
    }
  }
}
void solve() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    G[x].push_back(y);
    RG[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (val[i] == 1) dfs1(i);
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (val[i] == 2) dfs2(i);
  }
  for (int i = 1; i <= n; i++) {
    if (val[i] == 0) {
      if (f1[i] && f2[i])
        printf("1\n");
      else
        printf("0\n");
    } else if (val[i] == 1) {
      if (f2[i])
        printf("1\n");
      else
        printf("0\n");
    } else {
      if (f1[i])
        printf("1\n");
      else
        printf("0\n");
    }
  }
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
