#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
vector<int> adj[maxn], adjr[maxn];
int mark[maxn], ans[maxn];
int st[maxn];
void dfs1(int x) {
  mark[x] = 1;
  ans[x]++;
  for (int i = 0; i < (int)adj[x].size(); i++) {
    int u = adj[x][i];
    if (!mark[u]) dfs1(u);
  }
}
void dfs2(int x) {
  mark[x] = 1;
  ans[x]++;
  if (st[x] == 1) return;
  for (int i = 0; i < (int)adjr[x].size(); i++) {
    int u = adjr[x][i];
    if (!mark[u]) dfs2(u);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> st[i];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adjr[v].push_back(u);
  }
  for (int i = 0; i < n; i++)
    if (!mark[i] && st[i] == 1) dfs1(i);
  for (int i = 0; i < n; i++) mark[i] = 0;
  for (int i = 0; i < n; i++)
    if (!mark[i] && st[i] == 2) dfs2(i);
  for (int i = 0; i < n; i++)
    if (ans[i] == 2)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  return 0;
}
