#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
vector<int> nedge[MAXN];
int val[MAXN];
int ans[MAXN];
int mark[MAXN];
struct Node {
  int v, next;
} edge[100005 << 1];
int now[100005], head[100005];
int pre[100005], Index;
int low[100005], idx[100005], hash[100005];
int ss[100005], top;
int n, nn, len;
bool vis[MAXN];
void add_edge(int u, int v) {
  edge[len].v = v;
  edge[len].next = head[u];
  head[u] = len++;
}
void dfs(int u) {
  pre[u] = low[u] = Index++;
  ss[++top] = u;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (pre[v] == -1) {
      dfs(v);
      if (low[u] > low[v]) low[u] = low[v];
    } else if (idx[v] == -1) {
      if (low[u] > pre[v]) low[u] = pre[v];
    }
  }
  if (pre[u] == low[u]) {
    int v = -1;
    while (u != v) {
      v = ss[top--];
      idx[v] = nn;
    }
    now[nn++] = -1;
  }
}
void Trajan() {
  int i, j;
  memset(pre, -1, sizeof(int) * (n + 1));
  memset(idx, -1, sizeof(int) * (n + 1));
  Index = top = nn = 0;
  for (i = 1; i <= n; i++)
    if (pre[i] == -1) dfs(i);
  for (i = 1; i <= n; i++) {
    int s = idx[i];
    if (val[i] == 2) mark[s] = 1;
    for (j = head[i]; j != -1; j = edge[j].next) {
      int t = idx[edge[j].v];
      if (s == t) continue;
      nedge[s].push_back(t);
    }
    sort(nedge[s].begin(), nedge[s].end());
    nedge[s].erase(unique(nedge[s].begin(), nedge[s].end()), nedge[s].end());
  }
}
int dfs2(int u) {
  int i;
  if (vis[u]) return ans[u];
  if (mark[u]) ans[u] = 1;
  vis[u] = 1;
  for (i = 0; i < nedge[u].size(); i++) {
    int v = nedge[u][i];
    if (dfs2(v)) ans[u] = 1;
  }
  return ans[u];
}
int main() {
  int m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &val[i]);
  memset(head, -1, sizeof(head));
  len = 0;
  int x, y;
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    if (val[y] == 1) continue;
    add_edge(x, y);
  }
  Trajan();
  for (i = 1; i <= n; i++) {
    if (val[i] == 1) dfs2(idx[i]);
  }
  for (i = 1; i <= n; i++) printf("%d\n", ans[idx[i]]);
  return 0;
}
