#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
template <class T>
bool remax(T &a, const T &b) {
  return a < b ? (a = b, 1) : 0;
}
const int N = 100001;
int visited[N];
bool Nice[N];
bool interesting[N];
int state[N];
vector<int> G[N], G2[N];
int main() {
  int n, m;
  (scanf("%d %d", &(n), &(m)) == 2);
  for (int i = (1); i <= (n); ++i) (scanf("%d", &(state[i])) == 1);
  {
    int u, v;
    for (int mm = 0; mm < (m); ++mm) {
      (scanf("%d %d", &(u), &(v)) == 2);
      G[v].push_back(u);
      G2[u].push_back(v);
    }
  }
  vector<int> q;
  q.reserve(n);
  for (int i = (1); i <= (n); ++i) {
    if (state[i] == 2) {
      visited[i] = 1;
      q.push_back(i);
    }
  }
  for (typeof((q).begin()) i = ((q).begin()); i != (q).end(); ++i) {
    Nice[*i] = 1;
    for (typeof((G[*i]).begin()) u = ((G[*i]).begin()); u != (G[*i]).end();
         ++u) {
      if (state[*u] != 1 && remax(visited[*u], 1)) {
        q.push_back(*u);
      }
    }
  }
  {
    if (0) {
      cerr << ""
           << "visited"
           << ": ";
      for (int __i = ((1)); __i <= ((n)); ++__i) cerr << visited[__i] << " ";
      cerr << endl;
    }
  }
  q.clear();
  q.reserve(n);
  for (int i = (1); i <= (n); ++i) {
    if (Nice[i])
      for (typeof((G[i]).begin()) u = ((G[i]).begin()); u != (G[i]).end();
           ++u) {
        if (state[*u] == 1 && remax(visited[*u], 2)) {
          q.push_back(*u);
        }
      }
  }
  {
    if (0) {
      cerr << ""
           << "visited"
           << ": ";
      for (int __i = ((1)); __i <= ((n)); ++__i) cerr << visited[__i] << " ";
      cerr << endl;
    }
  }
  for (typeof((q).begin()) i = ((q).begin()); i != (q).end(); ++i) {
    interesting[*i] = 1;
    for (typeof((G2[*i]).begin()) u = ((G2[*i]).begin()); u != (G2[*i]).end();
         ++u) {
      if (state[*u] != 1 && remax(visited[*u], 2)) {
        q.push_back(*u);
      }
    }
  }
  {
    if (0) {
      cerr << ""
           << "visited"
           << ": ";
      for (int __i = ((1)); __i <= ((n)); ++__i) cerr << visited[__i] << " ";
      cerr << endl;
    }
  }
  for (int i = (1); i <= (n); ++i)
    printf("%d\n", interesting[i] && (state[i] == 1 || Nice[i]));
  return 0;
}
