#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> g[N], gt[N];
bool good2[N], good1[N], use[N];
int f[N], n, m;
void dfs2(int v) {
  use[v] = true;
  good2[v] = true;
  if (f[v] == 1) return;
  for (int i = 0; i < gt[v].size(); i++)
    if (!use[gt[v][i]]) dfs2(gt[v][i]);
}
void dfs1(int v) {
  use[v] = true;
  good1[v] = true;
  for (int i = 0; i < g[v].size(); i++)
    if (!use[g[v][i]]) dfs1(g[v][i]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &f[i]);
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    --x, --y;
    g[x].push_back(y);
    gt[y].push_back(x);
  }
  for (int i = 0; i < n; i++)
    if (!use[i] && f[i] == 2) dfs2(i);
  memset(use, 0, sizeof(use));
  for (int i = 0; i < n; i++)
    if (!use[i] && f[i] == 1) dfs1(i);
  for (int i = 0; i < n; i++) printf("%d\n", good1[i] * good2[i]);
  return 0;
}
