#include <bits/stdc++.h>
using namespace std;
short *f;
bool *fa;
bool *tu;
vector<long> *trans;
vector<long> *r_trans;
void color(long k) {
  fa[k] = true;
  for (long i = 0; i < trans[k].size(); i++) {
    if (!fa[trans[k][i]]) color(trans[k][i]);
  }
}
void r_color(long k) {
  tu[k] = true;
  if (f[k] == 1) return;
  for (long i = 0; i < r_trans[k].size(); i++) {
    if (!tu[r_trans[k][i]]) r_color(r_trans[k][i]);
  }
}
int main() {
  long n, m;
  cin >> n;
  cin >> m;
  f = new short[n];
  for (long i = 0; i < n; i++) cin >> f[i];
  trans = new vector<long>[n];
  r_trans = new vector<long>[n];
  for (long i = 0; i < m; i++) {
    long a, b;
    cin >> a >> b;
    trans[a - 1].push_back(b - 1);
    r_trans[b - 1].push_back(a - 1);
  }
  fa = new bool[n];
  tu = new bool[n];
  for (long i = 0; i < n; i++) fa[i] = false;
  for (long i = 0; i < n; i++) tu[i] = false;
  for (long i = 0; i < n; i++) {
    if (fa[i]) continue;
    if (f[i] == 1) color(i);
  }
  for (long i = 0; i < n; i++) {
    if (tu[i]) continue;
    if (f[i] == 2) r_color(i);
  }
  for (long i = 0; i < n; i++) {
    if (fa[i] && tu[i])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}
