#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int n, m, A[MAXN], c2[MAXN];
vector<int> G[MAXN], H[MAXN], C[MAXN];
bool used[MAXN], t2[MAXN];
int lw[MAXN], idx[MAXN], qidx, cmp[MAXN], qcmp;
vector<int> st;
void tjn(int u) {
  lw[u] = idx[u] = ++qidx;
  st.push_back(u);
  cmp[u] = -2;
  for (int v : G[u]) {
    if (!idx[v] || cmp[v] == -2) {
      if (!idx[v]) tjn(v);
      lw[u] = min(lw[u], lw[v]);
    }
  }
  if (lw[u] == idx[u]) {
    int x;
    do {
      x = st.back();
      st.pop_back();
      cmp[x] = qcmp;
    } while (x != u);
    qcmp++;
  }
}
void scc() {
  memset(idx, 0, sizeof(idx));
  qidx = 0;
  memset(cmp, -1, sizeof(cmp));
  qcmp = 0;
  for (int i = (0); i < (int)(n); i++)
    if (!idx[i]) tjn(i);
}
void dfs(int v) {
  used[v] = true;
  for (int i = (0); i < (int)(((int)H[v].size())); i++) {
    int w = H[v][i];
    if (!used[w]) dfs(w);
    t2[v] = t2[v] || t2[w];
  }
  t2[v] = t2[v] || c2[v];
}
int main() {
  while (scanf("%d %d", &n, &m) >= 1) {
    for (int i = (0); i < (int)(MAXN); i++) {
      G[i].clear();
      H[i].clear();
      C[i].clear();
    }
    for (int i = (0); i < (int)(n); i++) scanf("%d", &A[i]);
    for (int i = (0); i < (int)(m); i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      --a;
      --b;
      if (A[b] == 1) continue;
      G[a].push_back(b);
    }
    scc();
    memset(c2, false, sizeof(c2));
    for (int i = (0); i < (int)(n); i++) {
      C[cmp[i]].push_back(i);
      if (A[i] == 2) c2[cmp[i]] = true;
      for (int j = (0); j < (int)(((int)G[i].size())); j++) {
        int w = G[i][j];
        H[cmp[i]].push_back(cmp[w]);
      }
    }
    queue<int> Q;
    for (int i = (0); i < (int)(qcmp); i++) {
      sort(H[i].begin(), H[i].end());
      H[i].erase(unique(H[i].begin(), H[i].end()), H[i].end());
      if (((int)C[i].size()) == 1 && A[C[i][0]] == 1) Q.push(i);
    }
    memset(used, false, sizeof(used));
    memset(t2, false, sizeof(t2));
    while (!Q.empty()) {
      int v = Q.front();
      Q.pop();
      if (!used[v]) dfs(v);
    }
    for (int i = (0); i < (int)(n); i++) {
      printf("%d\n", t2[cmp[i]]);
    }
  }
  return 0;
}
