#include <bits/stdc++.h>
using namespace std;
const static int inf = 10000000;
const static int mod = 1000000007;
vector<vector<int> > adj;
vector<vector<int> > adj_rev;
vector<bool> assign;
vector<bool> use;
vector<int> f;
void dfs_assign(int now) {
  if (assign[now]) {
    return;
  }
  assign[now] = true;
  for (int i = 0; i < (int)(adj[now].size()); i++) {
    dfs_assign(adj[now][i]);
  }
}
void dfs_use(int now) {
  if (use[now]) {
    return;
  }
  use[now] = true;
  if (f[now] == 1) {
    return;
  }
  for (int i = 0; i < (int)(adj_rev[now].size()); i++) {
    dfs_use(adj_rev[now][i]);
  }
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    f.clear();
    f.resize(n);
    adj.clear();
    adj.resize(n);
    adj_rev.clear();
    adj_rev.resize(n);
    assign.clear();
    assign.resize(n, false);
    use.clear();
    use.resize(n, false);
    for (int i = 0; i < (int)(n); i++) {
      cin >> f[i];
    }
    for (int i = 0; i < (int)(m); i++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      adj[a].push_back(b);
      adj_rev[b].push_back(a);
    }
    for (int i = 0; i < (int)(n); i++) {
      if (f[i] == 1) {
        dfs_assign(i);
      } else if (f[i] == 2) {
        dfs_use(i);
      }
    }
    for (int i = 0; i < (int)(n); i++) {
      if (assign[i] && use[i]) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
  return 0;
}
