#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
const long long maxn = 1e5 + 10, LG = 30, mod = 1e9 + 7, inf = 1e18;
long long n, m, f[maxn];
vector<long long> in[maxn], out[maxn];
bool mk[maxn], km[maxn];
void dfs(long long v) {
  mk[v] = 1;
  for (auto u : out[v])
    if (!mk[u] && f[u] != 1) dfs(u);
}
void sfd(long long v) {
  km[v] = 1;
  if (f[v] == 1) return;
  for (auto u : in[v])
    if (!km[u] && f[u] != 2) sfd(u);
}
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 >> f[i];
  while (m--) {
    long long v, u;
    cin >> v >> u;
    out[v].push_back(u);
    in[u].push_back(v);
  }
  for (int i = 1; i <= n; i++)
    if (f[i] == 1) dfs(i);
  for (int i = 1; i <= n; i++)
    if (f[i] == 2) sfd(i);
  for (int i = 1; i <= n; i++) cout << (mk[i] && km[i]) << endl;
  return 0;
}
