#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline long long inl() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
inline double ind() {
  double x;
  scanf("%lf", &x);
  return x;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0) {
    int y = power(x, n / 2);
    return y * y;
  } else
    return x * power(x, n - 1);
}
vector<int> g[100010], grev[100010];
int n, m;
int f1[100010], f2[100010];
int a[100010], vis[100010];
void dfs1(int x) {
  vis[x] = 1;
  f1[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    if (!vis[g[x][i]]) dfs1(g[x][i]);
  }
}
void dfs2(int x) {
  vis[x] = 1;
  f2[x] = 1;
  if (a[x] == 1) return;
  for (int i = 0; i < grev[x].size(); i++) {
    if (!vis[grev[x][i]]) dfs2(grev[x][i]);
  }
}
int main() {
  n = in(), m = in();
  int i, j, x, y;
  for (i = 1; i <= n; i++) a[i] = in();
  for (i = 0; i < m; i++) {
    x = in(), y = in();
    g[x].push_back(y);
    grev[y].push_back(x);
  }
  memset(vis, 0, sizeof(vis));
  for (i = 1; i <= n; i++) {
    if (a[i] == 1 && !vis[i]) dfs1(i);
  }
  memset(vis, 0, sizeof(vis));
  for (i = 1; i <= n; i++) {
    if (a[i] == 2 && !vis[i]) dfs2(i);
  }
  for (i = 1; i <= n; i++) {
    if (f1[i] && f2[i])
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}
