#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000000;
int q[maxn], used1[maxn], used2[maxn], n, m, first[maxn];
vector<int> g[maxn], gi[maxn];
void Bfs1() {
  int head = 0, tail = 0;
  for (int i = 1; i <= n; ++i)
    if (first[i] == 1) {
      q[tail++] = i;
      used1[i] = true;
    }
  while (head != tail) {
    int v = q[head++];
    for (typeof(g[v].begin()) it = g[v].begin(); it != g[v].end(); ++it) {
      int to = *it;
      if (!used1[to] && (first[to] == 0 || first[to] == 2)) {
        q[tail++] = to;
        used1[to] = true;
      }
    }
  }
}
void Bfs2() {
  int head = 0, tail = 0;
  for (int i = 1; i <= n; ++i)
    if (first[i] == 2) {
      q[tail++] = i;
      used2[i] = true;
    }
  while (head != tail) {
    int v = q[head++];
    for (typeof(gi[v].begin()) it = gi[v].begin(); it != gi[v].end(); ++it) {
      int to = *it;
      if (!used2[to] && (first[to] == 0 || first[to] == 2)) {
        q[tail++] = to;
        used2[to] = true;
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &first[i]);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    gi[v].push_back(u);
  }
  Bfs1();
  Bfs2();
  for (int i = 1; i <= n; ++i) {
    if (used1[i] && used2[i])
      puts("1");
    else if (first[i] == 1) {
      bool found = false;
      for (typeof(g[i].begin()) it = g[i].begin(); it != g[i].end(); ++it) {
        int to = *it;
        if (first[to] == 0 || first[to] == 2) {
          if (used2[to]) {
            found = true;
            break;
          }
        }
      }
      if (found)
        puts("1");
      else
        puts("0");
    } else
      puts("0");
  }
  return 0;
}
