#include <bits/stdc++.h>
using namespace std;
const int targ = 10000000;
const int tg = 5;
template <typename T>
void printV(vector<T>& v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
template <typename T>
void printVs(vector<vector<T> >& v) {
  for (int i = 0; i < v.size(); i++) printVector(v[i]);
}
template <typename T>
void reverse(vector<T>& v) {
  for (int i = 0; i < (int)v.size() / 2; i++) swap(v[i], v[v.size() - 1 - i]);
}
int main() {
  int n, m;
  queue<int> S, F;
  cin >> n >> m;
  vector<int> canTo(n, 0), canFrom(n, 0);
  vector<int> st(n);
  vector<vector<int> > from(n), to(n);
  set<int> res;
  for (int i = 0; i < (int)n; i++) {
    cin >> st[i];
    if (st[i] == 1) S.push(i);
    if (st[i] == 2) F.push(i);
  }
  for (int i = 0; i < (int)m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    from[b].push_back(a);
    if (st[a] == 1 && st[b] == 2) {
      res.insert(a + 1);
      res.insert(b + 1);
    }
  }
  set<int> seen;
  while (!S.empty()) {
    int curr = S.front();
    S.pop();
    canTo[curr] = 1;
    for (int i = 0; i < (int)to[curr].size(); i++) {
      int a = to[curr][i];
      if (st[a] != 1 && seen.find(a) == seen.end()) {
        S.push(a);
        seen.insert(a);
      }
    }
  }
  seen.clear();
  while (!F.empty()) {
    int curr = F.front();
    F.pop();
    canFrom[curr] = 1;
    if (st[curr] != 1)
      for (int i = 0; i < (int)from[curr].size(); i++) {
        int a = from[curr][i];
        if (seen.find(a) == seen.end()) {
          F.push(a);
          seen.insert(a);
        }
      }
  }
  for (int i = 0; i < (int)n; i++) cout << (canTo[i] && canFrom[i]) << endl;
}
