#include <bits/stdc++.h>
using namespace std;
const int max_n = 100001;
int n, m;
vector<int> f;
vector<bool> ans, was1, was2;
vector<int> g1[max_n], g2[max_n];
void dfs1(int v) {
  was1[v] = true;
  for (int i = 0; i < g1[v].size(); i++)
    if (f[g1[v][i]] != 1 && !was1[g1[v][i]]) dfs1(g1[v][i]);
}
void dfs2(int v) {
  was2[v] = true;
  if (f[v] == 1) return;
  for (int i = 0; i < g2[v].size(); i++)
    if (!was2[g2[v][i]]) dfs2(g2[v][i]);
}
int main() {
  cin >> n >> m;
  f = vector<int>(n);
  ans = vector<bool>(n, false);
  was1 = vector<bool>(n, false);
  was2 = vector<bool>(n, false);
  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);
    if (f[i] == 2) dfs2(i);
  }
  for (int i = 0; i < n; i++) cout << (was1[i] && was2[i] ? 1 : 0) << endl;
  return 0;
}
