#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[1000008], in[1000008];
int tot, start[1000008], t[1000008];
struct arr {
  int x, y;
} a[1000008];
struct brr {
  int a, next;
} e[1000008];
void Add(int x, int y) {
  e[++tot].a = y;
  e[tot].next = start[x];
  start[x] = tot;
}
void Dfs(int u) {
  in[u] = 1;
  for (int i = start[u], v; v = e[i].a, i; i = e[i].next)
    if (!in[v]) Dfs(v);
}
void Dfs1(int u) {
  if (!in[u] || t[u]) return;
  t[u] = 1;
  if (f[u] == 1) return;
  for (int i = start[u], v; v = e[i].a, i; i = e[i].next) Dfs1(v);
}
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", &a[i].x, &a[i].y);
    Add(a[i].x, a[i].y);
  }
  for (int i = 1; i <= n; i++)
    if (f[i] == 1 && !in[i]) Dfs(i);
  tot = 0;
  memset(start, 0, sizeof(start));
  for (int i = 1; i <= m; i++) Add(a[i].y, a[i].x);
  for (int i = 1; i <= n; i++)
    if (f[i] == 2 && !t[i]) Dfs1(i);
  for (int i = 1; i <= n; i++) printf("%d\n", t[i]);
  return 0;
}
