#include <bits/stdc++.h>
using namespace std;
int f[100000];
vector<int> x[100000];
vector<int> y[100000];
bool r1[100000];
bool r2[100000];
int main() {
  int n, m;
  int a, b;
  vector<int> q;
  int t, c;
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> f[i];
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    --a;
    --b;
    if (f[b] != 1) {
      x[a].push_back(b);
      y[b].push_back(a);
    }
  }
  for (int i = 0; i < n; ++i) r1[i] = false;
  for (int i = 0; i < n; ++i)
    if (f[i] == 1) {
      q.clear();
      t = 0;
      q.push_back(i);
      r1[i] = true;
      while (t != (int)q.size()) {
        c = q[t];
        ++t;
        for (int j = 0; j < (int)x[c].size(); ++j)
          if (!r1[x[c][j]]) {
            q.push_back(x[c][j]);
            r1[x[c][j]] = true;
          }
      }
    }
  for (int i = 0; i < n; ++i) r2[i] = false;
  for (int i = 0; i < n; ++i)
    if (f[i] == 2) {
      q.clear();
      t = 0;
      q.push_back(i);
      r2[i] = true;
      while (t != (int)q.size()) {
        c = q[t];
        ++t;
        for (int j = 0; j < (int)y[c].size(); ++j)
          if (!r2[y[c][j]]) {
            q.push_back(y[c][j]);
            r2[y[c][j]] = true;
          }
      }
    }
  for (int i = 0; i < n; ++i) cout << (r1[i] && r2[i]) << "\n";
  return 0;
}
