#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
int n, m, a[MAX], vis[MAX], vis2[MAX];
vector<int> g[MAX], gt[MAX];
void dfs(int v) {
  for (auto u : g[v])
    if (!vis[u]) vis[u] = true, dfs(u);
}
void dfs2(int v) {
  for (auto u : gt[v])
    if (!vis2[u]) {
      vis2[u] = true;
      if (a[u] != 1) dfs2(u);
    }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1, x, y; i <= m; i++)
    cin >> x >> y, g[x].push_back(y), gt[y].push_back(x);
  for (int i = 1; i <= n; i++)
    if (a[i] == 1 && !vis[i])
      vis[i] = true, dfs(i);
    else if (a[i] == 2 && !vis2[i])
      vis2[i] = true, dfs2(i);
  for (int i = 1; i <= n; i++)
    if (vis[i] == true && vis2[i] == true)
      cout << "1\n";
    else
      cout << "0\n";
  return 0;
}
