#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <typename T>
inline bool remin(T& c, const T& n) {
  if (c > n) {
    c = n;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool remax(T& c, const T& n) {
  if (c < n) {
    c = n;
    return 1;
  }
  return 0;
}
int _in;
int in() {
  scanf("%d", &_in);
  return _in;
}
const int N = 1e5;
int state[N];
struct way {
  way(int v, int f) : used(v), graph(v), forbid(f) {}
  int forbid;
  vector<bool> used;
  vector<vector<int> > graph;
  void dfs(int v) {
    used[v] = true;
    if (state[v] != forbid) {
      vector<int>& cg = graph[v];
      int i;
      for ((i) = (0); (i) < ((cg).size()); ++(i))
        if (!used[cg[i]]) dfs(cg[i]);
    }
  }
};
int main() {
  int v, e, i, a, b;
  v = in();
  e = in();
  for ((i) = (0); (i) < (v); ++(i)) state[i] = in();
  way one(v, -1), two(v, 1);
  for ((i) = (0); (i) < (e); ++(i)) {
    a = in() - 1;
    b = in() - 1;
    one.graph[a].push_back(b);
    two.graph[b].push_back(a);
  }
  for ((i) = (0); (i) < (v); ++(i)) {
    if (state[i] == 1) one.dfs(i);
    if (state[i] == 2) two.dfs(i);
  }
  for ((i) = (0); (i) < (v); ++(i))
    puts(one.used[i] && two.used[i] ? "1" : "0");
  return 0;
}
