#include <bits/stdc++.h>
using namespace std;
int GET_INT() {
  int ret;
  scanf("%d", &ret);
  return ret;
}
int f[100005];
int nodes, edges;
bool seen[100005];
vector<int> adj[100005], adj_inv[100005];
bool isPure[100005];
bool interesting[100005];
void dfs_inv(int u) {
  isPure[u] = 1;
  seen[u] = 1;
  if (f[u] != 1) {
    for (int i = 0; i < (adj_inv[u].size()); ++i) {
      int v = adj_inv[u][i];
      if (!seen[v]) dfs_inv(v);
    }
  }
}
void dfs(int u) {
  if (isPure[u]) interesting[u] = true;
  seen[u] = 1;
  for (int i = 0; i < (adj[u].size()); ++i) {
    int v = adj[u][i];
    if (!seen[v]) dfs(v);
  }
}
int main() {
  scanf("%d%d", &nodes, &edges);
  for (int i = (1); i <= (nodes); ++i) scanf("%d", &f[i]);
  for (int i = 0; i < (edges); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj_inv[v].push_back(u);
  }
  memset(seen, (0), sizeof(seen));
  memset(isPure, (0), sizeof(isPure));
  for (int u = (1); u <= (nodes); ++u) {
    if (!seen[u] && f[u] == 2) {
      dfs_inv(u);
    }
  }
  memset(seen, (0), sizeof(seen));
  for (int u = (1); u <= (nodes); ++u) {
    if (!seen[u] && f[u] == 1) {
      dfs(u);
    }
  }
  for (int u = (1); u <= (nodes); ++u)
    if (interesting[u])
      puts("1");
    else
      puts("0");
  return 0;
}
