#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  int t = 1;
  while (t--) solve();
  return 0;
}
int d[101010];
vector<int> g[101010];
vector<int> obr[101010];
bool used1[101010];
bool used2[101010];
void dfs1(int v) {
  if (used1[v]) return;
  used1[v] = true;
  for (int i = 0; i < g[v].size(); ++i) {
    if (d[g[v][i]] != 1) dfs1(g[v][i]);
  }
}
void dfs2(int v) {
  if (used2[v]) return;
  used2[v] = true;
  if (d[v] == 1) return;
  for (int i = 0; i < obr[v].size(); ++i) {
    dfs2(obr[v][i]);
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    obr[b].push_back(a);
  }
  for (int i = 0; i < n; ++i) {
    if (d[i] == 1) {
      dfs1(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (d[i] == 2) dfs2(i);
  }
  for (int i = 0; i < n; ++i) {
    cout << (used1[i] && used2[i]) << endl;
  }
}
