#include <bits/stdc++.h>
using namespace std;
template <class Z>
inline bool checkmax(Z &a, Z b) {
  if (a == -1 || a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class Z>
inline bool checkmin(Z &a, Z b) {
  if (a == -1 || a > b) {
    a = b;
    return true;
  }
  return false;
}
int n, m;
int net[110000], size;
void init() {
  size = 0;
  memset(net, -1, sizeof(net));
}
struct EDGE {
  int v, next;
} edge[1100000];
void add(int u, int v) {
  edge[size].v = v;
  edge[size].next = net[u];
  net[u] = size++;
}
int val[110000];
int k;
bool vis[110000][2];
void dfs(int u) {
  vis[u][k] = 1;
  if (k == 1 && val[u] == 1) return;
  for (int i = net[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (vis[v][k]) continue;
    dfs(v);
  }
}
struct Road {
  int u, v;
} road[1100000];
int main() {
  int i, j, h;
  int a, b;
  while (scanf("%d%d", &n, &m) != EOF) {
    init();
    for (i = 1; i <= n; i++) {
      scanf("%d", &val[i]);
    }
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &a, &b);
      road[i].u = b;
      road[i].v = a;
      add(a, b);
    }
    memset(vis, 0, sizeof(vis));
    k = 0;
    for (i = 1; i <= n; i++) {
      if (val[i] == 1) dfs(i);
    }
    init();
    k = 1;
    for (i = 1; i <= m; i++) {
      add(road[i].u, road[i].v);
    }
    for (i = 1; i <= n; i++) {
      if (val[i] == 2) dfs(i);
    }
    for (i = 1; i <= n; i++) {
      puts(vis[i][0] && vis[i][1] ? "1" : "0");
    }
  }
  return 0;
}
