#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g1, g2;
int used[1000000];
bool ok1[1000000];
bool ok2[1000000];
int f[1000000];
void dfs1(int v, bool first) {
  if (used[v]) return;
  if (f[v] == 1 && !first) return;
  used[v] = 1;
  ok1[v] = 1;
  for (int i = 0; i < g1[v].size(); i++) dfs1(g1[v][i], 0);
}
void dfs2(int v) {
  if (used[v] == 1) return;
  used[v] = 1;
  ok2[v] = 1;
  if (f[v] == 1) return;
  for (int i = 0; i < g2[v].size(); i++) dfs2(g2[v][i]);
}
int main() {
  int n, m;
  cin >> n >> m;
  g1.resize(n);
  g2.resize(n);
  for (int i = 0; i < n; i++) cin >> f[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g1[a].push_back(b);
    g2[b].push_back(a);
  }
  for (int i = 0; i < n; i++)
    if (f[i] == 1) dfs1(i, 1);
  for (int i = 0; i < n; i++) used[i] = 0;
  for (int i = 0; i < n; i++)
    if (f[i] == 2) dfs2(i);
  for (int i = 0; i < n; i++)
    if (ok1[i] && ok2[i])
      cout << 1 << endl;
    else
      cout << 0 << endl;
}
