#include <bits/stdc++.h>
using namespace std;
vector<int> adj1[1000001], adj2[1000001];
bool vis1[1000001], vis2[1000001];
int n, m;
int state[1000001];
void dfs1(int x) {
  if (vis1[x]) return;
  vis1[x] = true;
  for (vector<int>::iterator vi = adj1[x].begin(); vi != adj1[x].end(); vi++)
    dfs1(*vi);
}
void dfs2(int x) {
  if (vis2[x]) return;
  vis2[x] = true;
  if (state[x] == 1) return;
  for (vector<int>::iterator vi = adj2[x].begin(); vi != adj2[x].end(); vi++)
    dfs2(*vi);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &state[i]);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj1[a].push_back(b);
    adj2[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (state[i] == 1) dfs1(i);
  for (int i = 1; i <= n; i++)
    if (state[i] == 2) dfs2(i);
  for (int i = 1; i <= n; i++)
    if (vis1[i] && vis2[i])
      puts("1");
    else
      puts("0");
}
