#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
int n, m;
int A[200000];
vector<int> G[200000];
vector<int> GG[200000];
bool B1[200000];
bool B2[200000];
void dfs1(int v) {
  B1[v] = true;
  for (int(i) = (0); (i) < (G[v].size()); ++(i)) {
    int to = G[v][i];
    if (B1[to] == false && A[to] != 1) dfs1(to);
  }
}
void dfs2(int v) {
  B2[v] = true;
  if (A[v] == 1) return;
  for (int(i) = (0); (i) < (GG[v].size()); ++(i)) {
    int to = GG[v][i];
    if (B2[to] == false) dfs2(to);
  }
}
int main() {
  cin >> n >> m;
  for (int(i) = (0); (i) < (n); ++(i)) scanf("%d", &A[i]);
  for (int(i) = (0); (i) < (m); ++(i)) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    G[u].push_back(v);
    GG[v].push_back(u);
  }
  for (int(i) = (0); (i) < (n); ++(i))
    if (B1[i] == false && A[i] == 1) dfs1(i);
  for (int(i) = (0); (i) < (n); ++(i))
    if (B2[i] == false && A[i] == 2) dfs2(i);
  for (int(i) = (0); (i) < (n); ++(i))
    if (B1[i] && B2[i])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  return 0;
}
