#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
int condition[MAXN];
bool used[MAXN], Tused[MAXN];
vector<vector<int> > g, Tg;
void dfs(int v) {
  used[v] = true;
  for (vector<int>::iterator it = g[v].begin(); it != g[v].end(); ++it)
    if (!used[*it]) dfs(*it);
}
void Tdfs(int v) {
  Tused[v] = true;
  if (condition[v] == 1) return;
  for (vector<int>::iterator it = Tg[v].begin(); it != Tg[v].end(); ++it)
    if (!Tused[*it]) Tdfs(*it);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  g.resize(n);
  Tg.resize(n);
  for (int i = 0; i < n; ++i) scanf("%d", &condition[i]);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u - 1].push_back(v - 1);
    Tg[v - 1].push_back(u - 1);
  }
  for (int i = 0; i < n; ++i) {
    if (!used[i] && condition[i] == 1) dfs(i);
    if (!Tused[i] && condition[i] == 2) Tdfs(i);
  }
  for (int i = 0; i < n; ++i) printf(used[i] && Tused[i] ? "1\n" : "0\n");
  return 0;
}
