#include <bits/stdc++.h>
using namespace std;
vector<int> G[1123456], G1[1123456];
int color1[1123456], color2[1123456], val[1123456];
void dfs1(int node) {
  if (color1[node]) return;
  color1[node] = 1;
  for (int i = 0; i < G[node].size(); i++) dfs1(G[node][i]);
}
void dfs2(int node) {
  if (color2[node]) return;
  color2[node] = 1;
  if (val[node] == 1) return;
  for (int i = 0; i < G1[node].size(); i++) dfs2(G1[node][i]);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> val[i];
  memset(color1, 0, sizeof color1);
  memset(color2, 0, sizeof color2);
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    G[--x].push_back(--y);
    G1[y].push_back(x);
  }
  for (int i = 0; i < n; i++)
    if (val[i] == 1) dfs1(i);
  for (int i = 0; i < n; i++)
    if (val[i] == 2) dfs2(i);
  for (int i = 0; i < n; i++) {
    if (color1[i] & color2[i])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
