#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[100010];
vector<int> adj[100010];
vector<int> rev[100010];
bool asg[100010];
bool usd[100010];
void dfs_asg(int v) {
  if (asg[v]) return;
  asg[v] = true;
  for (int i = 0; i < (int)(adj[v].size()); i++) dfs_asg(adj[v][i]);
}
void dfs_usd(int v) {
  if (usd[v]) return;
  usd[v] = true;
  if (A[v] == 1) return;
  for (int i = 0; i < (int)(rev[v].size()); i++) dfs_usd(rev[v][i]);
}
int main() {
  bool first = true;
  while (2 == scanf("%d%d", &N, &M)) {
    if (first)
      first = false;
    else
      puts("");
    for (int i = 0; i < (int)(N); i++) scanf("%d", &A[i]);
    for (int i = 0; i < (int)(N); i++) adj[i].clear(), rev[i].clear();
    for (int i = 0; i < (int)(M); i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      --a;
      --b;
      adj[a].push_back(b);
      rev[b].push_back(a);
    }
    memset(asg, 0, sizeof(asg));
    memset(usd, 0, sizeof(usd));
    for (int v = 0; v < (int)(N); v++) {
      if (A[v] == 1) dfs_asg(v);
      if (A[v] == 2) dfs_usd(v);
    }
    for (int v = 0; v < (int)(N); v++) printf("%d\n", asg[v] && usd[v] ? 1 : 0);
  }
  return 0;
}
