#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1000 * 1000 + 10;
vector<int> g[MaxN], gp[MaxN];
bool mark[MaxN], mark2[MaxN];
int val[MaxN];
void dfs(int v) {
  mark[v] = true;
  for (int i = 0; i < g[v].size(); i++)
    if (!mark[g[v][i]]) dfs(g[v][i]);
}
void dfs2(int v) {
  mark2[v] = 1;
  if (val[v] != 1)
    for (int i = 0; i < gp[v].size(); i++)
      if (!mark2[gp[v][i]]) dfs2(gp[v][i]);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> val[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    gp[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (val[i] == 1 && mark[i] == 0) dfs(i);
    if (val[i] == 2 && mark2[i] == 0) dfs2(i);
  }
  for (int i = 1; i <= n; i++)
    if (mark[i] == 1 && mark2[i] == 1)
      cout << "1" << endl;
    else
      cout << "0" << endl;
  return 0;
}
