#include <bits/stdc++.h>
using namespace std;
int getint() {
  unsigned int c;
  int x = 0;
  while (((c = getchar()) - '0') >= 10) {
    if (c == '-') return -getint();
    if (!~c) exit(0);
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while (((c = getchar()) - '0') < 10);
  return x;
}
const int ign = 0;
const int asn = 1;
const int use = 2;
const int N = 100100;
int n, m;
int state[N], a[N], b[N];
bool vis1[N], vis2[N], res[N];
vector<int> graph1[N];
vector<int> graph2[N];
void dfs1(int u) {
  if (vis1[u]) return;
  vis1[u] = 1;
  for (int i = 0; i < graph1[u].size(); i++) dfs1(graph1[u][i]);
}
void dfs2(int u) {
  if (vis2[u]) return;
  vis2[u] = 1;
  for (int i = 0; i < graph2[u].size(); i++) dfs2(graph2[u][i]);
}
int main() {
  int i, j, tcc, tc = 1 << 28;
  for (tcc = 0; tcc < tc; tcc++) {
    n = getint(), m = getint();
    for (i = 0; i < n; i++) state[i] = getint();
    for (i = 0; i < m; i++) {
      a[i] = getint() - 1;
      b[i] = getint() - 1;
    }
    memset(vis1, 0, sizeof(vis1));
    memset(vis2, 0, sizeof(vis2));
    memset(res, 0, sizeof(res));
    for (i = 0; i < n; i++) graph1[i].clear(), graph2[i].clear();
    for (i = 0; i < m; i++)
      if (state[b[i]] != asn) {
        graph1[a[i]].push_back(b[i]);
        graph2[b[i]].push_back(a[i]);
      }
    for (i = 0; i < n; i++)
      if (state[i] == asn) {
        dfs1(i);
      }
    for (i = 0; i < n; i++)
      if (state[i] == use) {
        dfs2(i);
      }
    for (i = 0; i < n; i++)
      if (vis1[i] and vis2[i]) res[i] = 1;
    for (i = 0; i < n; i++) {
      printf("%d\n", (int)res[i]);
    }
  }
  return 0;
}
