#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
vector<vector<int> > g, gr;
int tt[maxn];
bool used1[maxn], used2[maxn];
void dfs1(int v) {
  used1[v] = true;
  for (vector<int>::iterator it = g[v].begin(); it != g[v].end(); ++it)
    if (!used1[*it]) dfs1(*it);
}
void dfs2(int v) {
  used2[v] = true;
  for (vector<int>::iterator it = gr[v].begin(); it != gr[v].end(); ++it)
    if (!used2[*it]) dfs2(*it);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  g.resize(n), gr.resize(n);
  for (int i = 0; i < n; ++i) scanf("%d", &tt[i]);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    if (tt[b] != 1) {
      g[a].push_back(b);
      gr[b].push_back(a);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (tt[i] == 1) dfs1(i);
    if (tt[i] == 2) dfs2(i);
  }
  for (int i = 0; i < n; ++i) cout << (used1[i] && used2[i] ? 1 : 0) << endl;
  return 0;
}
