#include <bits/stdc++.h>
using namespace std;
const int inf(1010101010);
int n, m, f[100005];
vector<vector<int> > adj(100005), radj(100005);
vector<bool> reach1, reach2;
void dfs1(int x) {
  reach1[x] = true;
  for (__typeof((adj[x]).end()) it((adj[x]).begin()); it != ((adj[x]).end());
       ++it) {
    int y(*it);
    if (!reach1[y]) dfs1(y);
  }
}
void dfs2(int x) {
  reach2[x] = true;
  if (f[x] == 1) return;
  for (__typeof((radj[x]).end()) it((radj[x]).begin()); it != ((radj[x]).end());
       ++it) {
    int y(*it);
    if (!reach2[y]) dfs2(y);
  }
}
void solve() {
  if (!(cin >> n >> m)) exit(0);
  for (int i(0); i < (n); i++) adj[i].clear(), radj[i].clear();
  for (int i(0); i < (n); i++) cin >> f[i];
  while (m--) {
    int x, y;
    cin >> x >> y, x--, y--, adj[x].push_back(y), radj[y].push_back(x);
  }
  reach1 = vector<bool>(n), reach2 = vector<bool>(n);
  for (int i(0); i < (n); i++)
    if (f[i] == 1)
      if (!reach1[i]) dfs1(i);
  for (int i(0); i < (n); i++)
    if (f[i] == 2)
      if (!reach2[i]) dfs2(i);
  for (int i(0); i < (n); i++) printf("%d\n", reach1[i] && reach2[i]);
}
int main() {
  while (1) solve();
}
