#include <bits/stdc++.h>
using namespace std;
vector<int> edge[100010], redge[100010];
int f[100010], ans[100010], r[100010];
bool vis[100010];
int main() {
  int n, m;
  cin >> n >> m;
  for (__typeof(n) i = 0; i < (n); i++) scanf("%d", &f[i]);
  for (__typeof(m) i = 0; i < (m); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    edge[u].push_back(v);
    redge[v].push_back(u);
  }
  memset((ans), (-1), sizeof(ans));
  ;
  queue<int> q;
  for (__typeof(n) i = 0; i < (n); i++)
    if (f[i] == 1) {
      vis[i] = 1;
      q.push(i);
    }
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    for (__typeof(((int)edge[top].size())) i = 0; i < (((int)edge[top].size()));
         i++) {
      int v = edge[top][i];
      if (vis[v]) continue;
      vis[v] = true;
      if (f[v] == 2) ans[v] = 1;
      q.push(v);
    }
  }
  for (__typeof(n) i = 0; i < (n); i++) r[i] += vis[i];
  memset((vis), (0), sizeof(vis));
  ;
  for (__typeof(n) i = 0; i < (n); i++)
    if (f[i] == 2) {
      vis[i] = 1;
      q.push(i);
    }
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    for (__typeof(((int)redge[top].size())) i = 0;
         i < (((int)redge[top].size())); i++) {
      int v = redge[top][i];
      if (vis[v]) continue;
      vis[v] = true;
      if (f[v] == 1)
        ans[v] = 1;
      else
        q.push(v);
    }
  }
  for (__typeof(n) i = 0; i < (n); i++) r[i] += vis[i];
  for (__typeof(n) i = 0; i < (n); i++)
    if (f[i] == 0 && r[i] == 2) ans[i] = 1;
  for (__typeof(n) i = 0; i < (n); i++) printf("%d\n", ans[i] < 0 ? 0 : ans[i]);
  return 0;
}
