#include <bits/stdc++.h>
using namespace std;
long long gcd1(long long a, long long b) {
  if (a == 0) return b;
  return gcd1(b % a, a);
}
long long modx(long long base, long long ex) {
  long long ans = 1LL, val = base;
  while (ex > 0LL) {
    if (ex & 1LL) ans = (ans * val) % 1000000009LL;
    val = (val * val) % 1000000009LL;
    ex = ex >> 1LL;
  }
  return ans;
}
const int maxn = 1e5 + 10;
bool visit[maxn], visit1[maxn];
int n, m, x, y, a[maxn];
bool D[maxn], P[maxn];
vector<int> adj[maxn], v[maxn];
void dfs(int start) {
  visit[start] = true;
  for (int i = 0; i < adj[start].size(); i++) {
    int pt = adj[start][i];
    if (!visit[pt]) dfs(pt);
  }
}
void dfs2(int start) {
  visit1[start] = true;
  for (int i = 0; i < v[start].size(); i++) {
    int pt = v[start][i];
    if (!visit1[pt]) dfs2(pt);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    if (a[x] != 1 && a[y] != 1) v[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!visit[i] && a[i] == 1) dfs(i);
  }
  for (int i = 1; i <= n; i++) {
    if (!visit1[i] && a[i] == 2) dfs2(i);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != 1) continue;
    for (int j = 0; j < adj[i].size(); j++) {
      int pt = adj[i][j];
      if (visit1[pt] && a[pt] != 1) visit1[i] = true;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (visit1[i] && visit[i])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
