#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T maxer(T &a, T b) {
  a = max(a, b);
}
template <typename T>
inline T miner(T &a, T b) {
  a = min(a, b);
}
void iOS() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void fin() { freopen("in", "r", stdin); }
void fout() { freopen("out", "w", stdout); }
const int inf = ~0u / 10;
const long long linf = ~0ull / 20;
const int maxn = 1e5 + 20;
;
vector<int> adj[maxn], radj[maxn];
bool vis[maxn], rvis[maxn];
int st[maxn];
void dfs(int v, int d = -1) {
  if (st[v] == 1 && d != -1) return;
  vis[v] = 1;
  for (int x : adj[v])
    if (!vis[x]) dfs(x, 0);
}
void rdfs(int v, int d = -1) {
  rvis[v] = 1;
  if (st[v] == 1) return;
  for (int x : radj[v])
    if (!rvis[x]) rdfs(x, 0);
}
int main() {
  iOS();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> st[i];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    radj[v].push_back(u);
  }
  for (int i = 0; i < n; i++)
    if (st[i] == 1) dfs(i);
  for (int i = 0; i < n; i++)
    if (st[i] == 2) rdfs(i);
  for (int i = 0; i < n; i++)
    if (vis[i] && rvis[i])
      cout << 1 << '\n';
    else
      cout << 0 << '\n';
  return 0;
}
