#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const double EPS = 1e-10;
const int SZ = 100010;
bool visit_a[SZ], visit_u[SZ];
int f[SZ];
vector<int> G[SZ];
vector<int> rG[SZ];
void bfs(bool *visit, int a, int N, const vector<int> *g) {
  queue<int> que;
  fill(visit, visit + N, false);
  for (int i = 0; i < N; i++) {
    if (f[i] == a) {
      que.push(i);
      visit[i] = true;
    }
  }
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int i = 0; i < (int)g[v].size(); i++) {
      int to = g[v][i];
      if (!visit[to] && f[to] != a) {
        visit[to] = true;
        if (f[to] != 1) que.push(to);
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &f[i]);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    G[a].push_back(b);
    rG[b].push_back(a);
  }
  bfs(visit_a, 1, n, G);
  bfs(visit_u, 2, n, rG);
  for (int i = 0; i < n; i++) {
    if (visit_a[i] && visit_u[i]) {
      puts("1");
    } else {
      puts("0");
    }
  }
  return 0;
}
