#include <bits/stdc++.h>
using namespace std;
int n, m, a[100015], x, y;
vector<int> G[100015], F[100015];
bool vis1[100015], vis2[100015];
void dfs(int o) {
  vis1[o] = 1;
  for (int i = 0; i < G[o].size(); ++i) {
    if (vis1[G[o][i]]) continue;
    dfs(G[o][i]);
  }
}
void DFS(int o) {
  vis2[o] = 1;
  if (a[o] == 1) return;
  for (int i = 0; i < F[o].size(); ++i) {
    if (vis2[F[o][i]]) continue;
    DFS(F[o][i]);
  }
}
int main() {
  int i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (i = 0; i < m; ++i) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    F[y].push_back(x);
  }
  for (i = 1; i <= n; ++i)
    if (a[i] == 1) dfs(i);
  for (i = 1; i <= n; ++i)
    if (a[i] == 2) DFS(i);
  for (i = 1; i <= n; ++i) {
    printf("%d\n", vis1[i] && vis2[i]);
  }
  return 0;
}
