#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[100000];
vector<int> d[100000], dd[100000];
int v1[100000], v2[100000];
int qu[100000], qs, qe;
int main() {
  int i, j, k, p, q;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%d", &f[i]);
  for (i = 0; i < n; i++) {
    d[i].clear();
    dd[i].clear();
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d", &j, &k);
    j--;
    k--;
    d[j].push_back(k);
    dd[k].push_back(j);
  }
  memset(v1, 0, sizeof(v1));
  qs = qe = 0;
  for (i = 0; i < n; i++) {
    if (f[i] == 1) {
      qu[qe++] = i;
      v1[i] = 1;
    }
  }
  while (qs < qe) {
    p = qu[qs++];
    for (i = 0; i < d[p].size(); i++) {
      q = d[p][i];
      if (f[q] != 1 && !v1[q]) {
        qu[qe++] = q;
        v1[q] = 1;
      }
    }
  }
  memset(v2, 0, sizeof(v2));
  qs = qe = 0;
  for (i = 0; i < n; i++) {
    if (f[i] == 2) {
      qu[qe++] = i;
      v2[i] = 1;
    }
  }
  while (qs < qe) {
    p = qu[qs++];
    if (f[p] == 1) continue;
    for (i = 0; i < dd[p].size(); i++) {
      q = dd[p][i];
      if (!v2[q]) {
        qu[qe++] = q;
        v2[q] = 1;
      }
    }
  }
  for (i = 0; i < n; i++) printf("%d\n", v1[i] && v2[i]);
  return 0;
}
