#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
vector<int> v[maxn], w[maxn];
long long a[maxn];
bool d[maxn];
long long c[maxn][5];
long long n, m;
bool mark[maxn][2];
void dfs1(long long i) {
  c[i][0] = 1;
  mark[i][0] = 1;
  for (long long y = 0; y < v[i].size(); y++) {
    if (!mark[v[i][y]][0]) {
      dfs1(v[i][y]);
    }
  }
}
void dfs2(long long i) {
  mark[i][1] = 1;
  c[i][1] = 1;
  if (a[i] == 1) return;
  for (long long y = 0; y < w[i].size(); y++) {
    if (!mark[w[i][y]][1]) {
      dfs2(w[i][y]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (long long y = 1; y <= n; y++) {
    cin >> a[y];
    if (a[y] == 1) {
      v[100000 + 1].push_back(y);
    }
    if (a[y] == 2) {
      w[100000 + 1].push_back(y);
    }
  }
  while (m--) {
    long long i, j;
    cin >> i >> j;
    v[i].push_back(j);
    w[j].push_back(i);
  }
  dfs1(100000 + 1);
  dfs2(100000 + 1);
  for (long long y = 1; y <= n; y++) {
    cout << (c[y][0] && c[y][1]) << endl;
  }
}
