#include <bits/stdc++.h>
using namespace std;
int n, m, f[100010];
vector<int> adj1[100010], adj2[100010];
bool vis[2][100010];
queue<int> q;
void Init() {
  int i, u, v;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%d", f + i);
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    adj1[u].push_back(v);
    adj2[v].push_back(u);
  }
}
void BFS1() {
  for (int i = 1; i <= n; ++i)
    if (f[i] == 1) vis[0][i] = true, q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : adj1[u]) {
      if (vis[0][v]) continue;
      vis[0][v] = true;
      q.push(v);
    }
  }
}
void BFS2() {
  for (int i = 1; i <= n; ++i)
    if (f[i] == 2) vis[1][i] = true, q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (f[u] == 1) continue;
    for (int v : adj2[u]) {
      if (vis[1][v]) continue;
      vis[1][v] = true;
      q.push(v);
    }
  }
}
int main() {
  Init();
  BFS1();
  BFS2();
  for (int i = 1; i <= n; ++i) printf("%d\n", (vis[0][i] && vis[1][i]) ? 1 : 0);
  return 0;
}
