#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
int n, m, type[N], u[N], uu[N];
vector<int> g[N], b[N];
void dfs(int v) {
  if (u[v]) return;
  u[v] = 1;
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    dfs(to);
  }
}
void Dfs(int v) {
  if (uu[v]) return;
  uu[v] = 1;
  if (type[v] == 1) return;
  for (int i = 0; i < (int)b[v].size(); i++) {
    int to = b[v][i];
    Dfs(to);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> type[i];
  }
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    if (l == r) continue;
    g[l].push_back(r);
    b[r].push_back(l);
  }
  for (int i = 0; i < n; i++)
    if (type[i] == 1) {
      dfs(i);
    }
  for (int i = 0; i < n; i++)
    if (type[i] == 2) {
      Dfs(i);
    }
  for (int i = 0; i < n; i++) {
    cout << (u[i] & uu[i]) << "\n";
  }
  return 0;
}
