#include <bits/stdc++.h>
using namespace std;
int f[200000];
vector<int> g[200000];
vector<int> gr[200000];
bool used1[200000];
bool used2[200000];
void dfs1(int v) {
  used1[v] = 1;
  for (int(i) = (0); (i) < (g[v].size()); ++(i)) {
    int t = g[v][i];
    if (!used1[t]) dfs1(t);
  }
}
void dfs2(int v) {
  used2[v] = 1;
  for (int(i) = (0); (i) < (gr[v].size()); ++(i)) {
    int t = gr[v][i];
    if (!used2[t]) dfs2(t);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int(i) = (0); (i) < (n); ++(i)) scanf("%d", &f[i]);
  for (int(i) = (0); (i) < (m); ++(i)) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    if (f[b] != 1) {
      g[a].push_back(b);
      gr[b].push_back(a);
    }
  }
  for (int(i) = (0); (i) < (n); ++(i)) {
    if (f[i] == 1 && !used1[i]) dfs1(i);
    if (f[i] == 2 && !used2[i]) dfs2(i);
  }
  for (int(i) = (0); (i) < (n); ++(i))
    if (used1[i] && used2[i])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  return 0;
}
