#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const double eps = 1e-9;
vector<int> e1[N], e2[N];
int n, m, f[N], from[N], to[N];
void gao(int u) {
  from[u] = 1;
  for (int i = 0; i < e1[u].size(); i++) {
    if (!from[e1[u][i]]) gao(e1[u][i]);
  }
}
void cao(int u) {
  to[u] = 1;
  if (f[u] == 1) return;
  for (int i = 0; i < e2[u].size(); i++) {
    if (!to[e2[u][i]]) cao(e2[u][i]);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
  }
  while (m--) {
    int u, v;
    cin >> u >> v;
    e1[u].push_back(v);
    e2[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!from[i] && f[i] == 1) {
      gao(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!to[i] && f[i] == 2) {
      cao(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (from[i] && to[i]) {
      puts("1");
    } else
      puts("0");
  }
  return 0;
}
