#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double Pi = acos(-1.0);
const double EPS = 1e-8;
int n, m, f[N], st[N];
bool vis[N];
vector<int> e[N], g[N];
queue<int> que;
void bfs(int c, const vector<int> e[]) {
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    st[u] |= c;
    if (c != 1 && f[u] == 1) continue;
    for (int i = (0); i < (((int)(e[u]).size())); ++i) {
      int v = e[u][i];
      if (!vis[v]) vis[v] = true, que.push(v);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i < (n + 1); ++i) scanf("%d", f + i), vis[i] = false;
  for (int i = (0); i < (m); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v), g[v].push_back(u);
  }
  memset(vis, false, sizeof(vis[0]) * (n + 1));
  for (int i = (1); i < (n + 1); ++i)
    if (f[i] == 1) vis[i] = true, que.push(i);
  bfs(1, e);
  memset(vis, false, sizeof(vis[0]) * (n + 1));
  for (int i = (1); i < (n + 1); ++i)
    if (f[i] == 2) vis[i] = true, que.push(i);
  bfs(2, g);
  for (int i = (1); i < (n + 1); ++i) printf("%d\n", st[i] == 3);
  return 0;
}
