#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
const int MOD = 1000000007;
int mod = 999998639;
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  long long d = exgcd(b, a % b, x, y);
  long long z = x;
  x = y, y = z - y * (a / b);
  return d;
}
inline long long qpow(long long b, long long e, long long m = MOD) {
  long long a = 1;
  for (; e; e >>= 1, b = b * b % m)
    if (e & 1) a = a * b % m;
  return a;
}
int f[maxn];
vector<int> ve[maxn], VE[maxn];
int vis[maxn], ans[maxn];
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < ve[x].size(); i++) {
    int y = ve[x][i];
    if (f[y] == 1) continue;
    if (vis[y]) continue;
    dfs(y);
  }
}
void dfss(int x) {
  ans[x] = 1;
  if (f[x] == 1) return;
  for (int i = 0; i < VE[x].size(); i++) {
    int y = VE[x][i];
    if (ans[y]) continue;
    dfss(y);
  }
}
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(vis, 0, sizeof(vis));
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i <= n; i++) ve[i].clear(), VE[i].clear();
    for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      ve[u].push_back(v);
      VE[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
      if (f[i] == 1) {
        dfs(i);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (f[i] == 2 && !ans[i]) {
        dfss(i);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (vis[i] && ans[i])
        printf("1\n");
      else
        printf("0\n");
    }
  }
}
