#include <bits/stdc++.h>
#pragma warning(disable : 4244 4267 4018 4996 4800)
using namespace std;
istream& in = cin;
ostream& out = cout;
int main() {
  int n, m;
  in >> n >> m;
  vector<vector<int> > e(n), re(n);
  vector<int> f(n);
  for (int i = 0; i < n; ++i) in >> f[i];
  for (int i = 0; i < m; ++i) {
    int a, b;
    in >> a >> b;
    --a, --b;
    e[a].push_back(b);
    re[b].push_back(a);
  }
  vector<int> res(n), found(n);
  for (int i = 0; i < n; ++i)
    if (f[i] == 2 && !found[i]) {
      queue<int> q;
      q.push(i);
      found[i] = 1;
      while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int j = 0; j < re[v].size(); ++j) {
          int w = re[v][j];
          if (f[w] == 1)
            found[w] = 1;
          else if (f[w] != 1 && !found[w]) {
            found[w] = 1;
            q.push(w);
          }
        }
      }
    }
  for (int i = 0; i < n; ++i)
    if (f[i] == 1 && found[i]) {
      queue<int> q;
      res[i] = 1;
      q.push(i);
      while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int j = 0; j < e[v].size(); ++j) {
          int w = e[v][j];
          if (f[w] != 1 && found[w] && !res[w]) {
            res[w] = 1;
            q.push(w);
          }
        }
      }
    }
  copy((res).begin(), (res).end(), ostream_iterator<int>(cout, "\n"));
  return 0;
}
