#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
const int N = 100009;
vector<int> st;
vector<vector<int> > g;
vector<vector<int> > gi;
vector<int> imp;
int used[N];
int dos[N];
void dfs1(int v) {
  dos[v] = 1;
  if (st[v] == 1) {
    return;
  }
  for (long long i = 0; i < (int)(gi[v]).size(); i++) {
    int to = gi[v][i];
    if (!dos[to]) {
      dfs1(to);
    }
  }
}
void dfs(int v) {
  used[v] = 1;
  if (dos[v]) {
    imp[v] = 1;
  }
  for (long long i = 0; i < (int)(g[v]).size(); i++) {
    int to = g[v][i];
    if (!used[to] && st[to] != 1) {
      dfs(to);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  st.resize(n);
  imp.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> st[i];
  }
  g.resize(n);
  gi.resize(n);
  for (long long i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    gi[b].push_back(a);
  }
  for (long long i = 0; i < n; i++) {
    if (st[i] == 2 && !dos[i]) {
      dfs1(i);
    }
  }
  for (long long i = 0; i < n; i++) {
    if (st[i] == 1 && !used[i]) {
      dfs(i);
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << imp[i] << endl;
  }
  return 0;
}
