#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 144, mod = 998244353, inF = 1e9 + 7, LOG = 20;
const long long inf = 2e18;
const double pi = acos(-1), eps = 1e-9;
int n, m;
int a[N];
vector<int> g[N], ug[N];
int p[N], d[N];
bool was[N];
long long bp(long long x, long long y) {
  x %= mod;
  if (y == 0) return 1;
  if (y & 1) return (x * bp(x, y - 1)) % mod;
  long long z = bp(x, y / 2);
  return (z * z) % mod;
}
void file() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
void dfs(int x) {
  p[x] = 1;
  for (auto to : g[x]) {
    if (!p[to]) dfs(to);
  }
}
void udfs(int x) {
  d[x] = 1;
  if (a[x] == 1) return;
  for (auto to : ug[x]) {
    if (!d[to]) udfs(to);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    ug[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!was[i] && a[i] == 1) {
      dfs(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    was[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (!was[i] && a[i] == 2) {
      udfs(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << min(p[i], d[i]) << "\n";
  }
  return 0;
}
