#include <bits/stdc++.h>
using namespace std;
vector<bool> bfs(size_t n, const vector<vector<int> >& g,
                 const vector<int>& start, vector<bool> denied) {
  queue<int> q;
  vector<bool> used(n, false);
  for (size_t i = 0; i < start.size(); i++) {
    q.push(start[i]);
    used[start[i]] = true;
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    if (denied[now]) continue;
    for (size_t i = 0; i < g[now].size(); i++) {
      int to = g[now][i];
      if (!used[to]) {
        used[to] = true;
        q.push(to);
      }
    }
  }
  return used;
}
int main() {
  size_t n, m;
  cin >> n >> m;
  vector<int> type(n);
  for (size_t i = 0; i < n; i++) cin >> type[i];
  vector<vector<int> > g(n, vector<int>());
  vector<vector<int> > revG(n, vector<int>());
  for (size_t i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    revG[b].push_back(a);
  }
  vector<int> start1;
  vector<int> start2;
  vector<bool> denied1(n, false);
  vector<bool> denied2(n, false);
  for (size_t i = 0; i < n; i++) {
    if (type[i] == 1) {
      start1.push_back(i);
      denied2[i] = true;
    }
    if (type[i] == 2) {
      start2.push_back(i);
    }
  }
  vector<bool> reached1 = bfs(n, g, start1, denied1);
  vector<bool> reached2 = bfs(n, revG, start2, denied2);
  for (size_t i = 0; i < n; i++)
    cout << ((reached1[i] && reached2[i]) ? 1 : 0) << "\n";
}
