#include <bits/stdc++.h>
using namespace std;
const int size = 100002;
int states[size];
vector<int> g[size], revg[size];
bool mark1[size], mark2[size];
void DFS(int idx) {
  mark1[idx] = 1;
  for (int i = 0; i < ((int)(g[idx]).size()); i++) {
    if (!mark1[g[idx][i]]) DFS(g[idx][i]);
  }
}
void DFS2(int idx) {
  mark2[idx] = 1;
  if (states[idx] == 1) return;
  for (int i = 0; i < ((int)(revg[idx]).size()); i++) {
    if (!mark2[revg[idx][i]]) DFS2(revg[idx][i]);
  }
}
int main() {
  int n, m, a, b;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", states + i);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    --a, --b;
    g[a].push_back(b);
    revg[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    if (states[i] == 1) DFS(i);
    if (states[i] == 2) DFS2(i);
  }
  for (int i = 0; i < n; i++) printf(mark1[i] && mark2[i] ? "1\n" : "0\n");
}
