#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100009;
const double eps = 1e-9;
int n, m, a, b;
vector<vector<int> > G;
vector<vector<int> > GT;
int color[MAXN];
int fromin[MAXN];
int fromout[MAXN];
bool used1[MAXN];
bool used2[MAXN];
void dfs1(int v) {
  if (used1[v]) return;
  fromin[v] = 1;
  used1[v] = 1;
  for (int to : G[v]) {
    fromin[to] = 1;
    if (!used1[to]) {
      dfs1(to);
    }
  }
}
void dfs2(int v) {
  if (used2[v]) return;
  fromout[v] = 1;
  used2[v] = 1;
  for (int to : GT[v]) {
    fromout[to] = 1;
    if (!used2[to] && color[to] != 1) {
      dfs2(to);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  G.resize(n);
  GT.resize(n);
  for (int i = 0, _n = (n); i < _n; i++) scanf("%d", &color[i]);
  for (int i = 0, _n = (m); i < _n; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    G[a].push_back(b);
    GT[b].push_back(a);
  }
  for (int i = 0, _n = (n); i < _n; i++) {
    if (!used1[i] && color[i] == 1) dfs1(i);
    if (!used2[i] && color[i] == 2) dfs2(i);
  }
  for (int i = 0, _n = (n); i < _n; i++) {
    if (fromin[i] && fromout[i])
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}
