#include <bits/stdc++.h>
using namespace std;
vector<int> g[200000], gr[200000];
bool used[200000], usedgr[200000];
int l, r, n, m, f[200000];
void dfs1(int v) {
  used[v] = true;
  for (int i = 0; i < g[v].size(); i++)
    if (!used[g[v][i]]) dfs1(g[v][i]);
}
void dfs2(int v) {
  usedgr[v] = true;
  if (f[v] == 1) return;
  for (int i = 0; i < gr[v].size(); i++)
    if (!usedgr[gr[v][i]]) dfs2(gr[v][i]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &r);
    g[l].push_back(r);
    gr[r].push_back(l);
  }
  for (int i = 1; i <= n; i++) {
    if (f[i] == 1 && !used[i]) dfs1(i);
    if (f[i] == 2 && !usedgr[i]) dfs2(i);
  }
  for (int i = 1; i <= n; i++) printf("%d\n", used[i] & usedgr[i]);
  return 0;
}
