#include <bits/stdc++.h>
using namespace std;
namespace {
const int kMaxN = 100000, kMaxM = 100000;
int n, m, f[kMaxN];
bool vis[2][kMaxN];
struct Graph {
  int cnt, begin[kMaxN], end[kMaxM], next[kMaxM];
  Graph() : cnt(0) { memset(begin, -1, sizeof(begin)); }
  void add_edge(int u, int v) {
    next[cnt] = begin[u];
    begin[u] = cnt;
    end[cnt++] = v;
  }
} g[2];
void Dfs(int gr, int u) {
  vis[gr][u] = true;
  if (gr == 1 && f[u] == 1) return;
  for (int now = g[gr].begin[u], v; now != -1; now = g[gr].next[now])
    if (!vis[gr][v = g[gr].end[now]]) Dfs(gr, v);
}
void Solve(FILE *fin, FILE *fout) {
  fscanf(fin, "%d%d", &n, &m);
  for (int i = 0; i < n; ++i) fscanf(fin, "%d", &f[i]);
  for (int u, v; m--;) {
    fscanf(fin, "%d%d", &u, &v);
    --u, --v;
    g[0].add_edge(u, v);
    g[1].add_edge(v, u);
  }
  for (int i = 0; i < n; ++i) {
    if (f[i] == 1 && !vis[0][i]) Dfs(0, i);
    if (f[i] == 2 && !vis[1][i]) Dfs(1, i);
  }
  for (int i = 0; i < n; ++i) fprintf(fout, "%d\n", vis[0][i] && vis[1][i]);
}
}  // namespace
int main() {
  ::Solve(stdin, stdout);
  return 0;
}
