#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int maxm = maxn;
int a[maxn];
bool vis[maxn], vis2[maxn];
int n, m;
vector<int> child[maxm], child2[maxm];
void dfs(int u) {
  vector<int>::iterator it;
  vis[u] = true;
  for (it = child[u].begin(); it != child[u].end(); ++it)
    if (!vis[*it]) dfs(*it);
}
void dfs2(int u) {
  vector<int>::iterator it;
  vis2[u] = true;
  if (a[u] == 1) return;
  for (it = child2[u].begin(); it != child2[u].end(); ++it)
    if (!vis2[*it]) dfs2(*it);
}
int main() {
  while (cin >> n >> m) {
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int u, v;
    for (int i = 1; i <= m; ++i) {
      cin >> u >> v;
      child[u].push_back(v);
      child2[v].push_back(u);
    }
    for (int i = 1; i <= n; ++i) {
      if (a[i] == 1 && !vis[i]) dfs(i);
      if (a[i] == 2 && !vis2[i]) dfs2(i);
    }
    for (int i = 1; i <= n; ++i) cout << (vis[i] && vis2[i]) << endl;
  }
}
