#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:67108864")
using namespace std;
const int maxn = 200100;
int ans[maxn], ans2[maxn];
int state[maxn];
vector<vector<pair<int, int>>> g, tr_g;
bool vis1[maxn], vis2[maxn];
int color[maxn];
int n, m;
void dfs1(int v) {
  if (vis1[v]) return;
  vis1[v] = true;
  for (auto it = g[v].begin(); it != g[v].end(); it++) dfs1(it->first);
}
void dfs2(int v) {
  if (vis2[v]) return;
  vis2[v] = true;
  if (state[v] == 1) return;
  for (auto it = tr_g[v].begin(); it != tr_g[v].end(); it++) dfs2(it->first);
}
vector<int> order;
int main() {
  scanf("%d%d", &n, &m);
  g.assign(n, vector<pair<int, int>>());
  tr_g.assign(n, vector<pair<int, int>>());
  for (int i = 0; i < n; i++) scanf("%d", &state[i]);
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int from, to;
    scanf("%d%d", &from, &to);
    from--, to--;
    g[from].push_back(make_pair(to, cnt));
    tr_g[to].push_back(make_pair(from, cnt++));
  }
  for (int i = 0; i < n; i++)
    if (state[i] == 1) dfs1(i);
  for (int i = 0; i < n; i++)
    if (state[i] == 2) dfs2(i);
  for (int i = 0; i < n; i++) printf("%d\n", (vis1[i] && vis2[i]) ? 1 : 0);
  return 0;
}
