#include <bits/stdc++.h>
using namespace std;
vector<int> p;
vector<int> graph[100007], graph2[100007];
int vis[100007];
int vis2[100007];
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  for (int(i) = (int)(0); (i) < (int)(graph[x].size()); ++(i)) dfs(graph[x][i]);
}
void dfs2(int x) {
  if (vis2[x]) return;
  vis2[x] = 1;
  if (p[x] == 1) return;
  for (int(i) = (int)(0); (i) < (int)(graph2[x].size()); ++(i))
    dfs2(graph2[x][i]);
}
int main() {
  int n, m;
  cin >> n >> m;
  p.resize(n);
  for (int(i) = (int)(0); (i) < (int)(n); ++(i)) cin >> p[i];
  for (int(i) = (int)(0); (i) < (int)(m); ++(i)) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    graph[a].push_back(b);
    graph2[b].push_back(a);
  }
  memset(vis, 0, sizeof(vis));
  for (int(i) = (int)(0); (i) < (int)(n); ++(i))
    if (!vis[i] && p[i] == 1) dfs(i);
  memset(vis2, 0, sizeof(vis2));
  for (int(i) = (int)(0); (i) < (int)(n); ++(i))
    if (!vis2[i] && p[i] == 2) dfs2(i);
  for (int(i) = (int)(0); (i) < (int)(n); ++(i)) {
    if (vis[i] && vis2[i])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
