#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int f[n], res[n];
  map<int, vector<int> > fo, bc;
  queue<int> que, que2;
  set<int> visited;
  for (int i = 0; i < n; i++) {
    cin >> f[i];
    res[i] = 0;
    if (f[i] == 2)
      que.push(i);
    else if (f[i] == 1) {
      que2.push(i);
      visited.insert(i);
    }
  }
  for (int i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    a--, b--;
    fo[a].push_back(b);
    bc[b].push_back(a);
  }
  while (!que.empty()) {
    int b = que.front();
    que.pop();
    for (auto it = bc[b].begin(); it != bc[b].end(); it++)
      if (f[*it] == 0) {
        que.push(*it);
        f[*it] = 2;
      }
  }
  while (!que2.empty()) {
    int a = que2.front();
    que2.pop();
    for (auto it = fo[a].begin(); it != fo[a].end(); it++)
      if (f[*it] == 2) {
        if (visited.find(*it) == visited.end()) {
          que2.push(*it);
          visited.insert(*it);
        }
        res[*it] = 1;
        res[a] = 1;
      }
  }
  for (int i = 0; i < n; i++) cout << res[i] << endl;
}
