#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (100000 + 100);
int N, M, val[MAX_N], vis1[MAX_N], vis2[MAX_N];
int path[MAX_N];
vector<int> g1[MAX_N], g2[MAX_N];
void dfs(int u) {
  vis1[u] = 1;
  for (int i = (0); i < ((int)g1[u].size()); ++i) {
    int v = g1[u][i];
    if (!vis1[v] && val[v] != 1) dfs(v);
  }
}
void rdfs(int u) {
  vis2[u] = 1;
  if (val[u] == 1) return;
  for (int i = (0); i < ((int)g2[u].size()); ++i) {
    int v = g2[u][i];
    if (!vis2[v]) rdfs(v);
  }
}
int main() {
  cin >> N >> M;
  for (int i = (1); i <= (N); ++i) cin >> val[i];
  for (int i = (1); i <= (M); ++i) {
    int u, v;
    cin >> u >> v;
    g1[u].push_back(v);
    g2[v].push_back(u);
  }
  for (int i = (1); i <= (N); ++i) {
    if (val[i] == 1)
      dfs(i);
    else if (val[i] == 2)
      rdfs(i);
  }
  for (int i = (1); i <= (N); ++i) printf("%d\n", (vis1[i] & vis2[i]));
  return 0;
}
