#include <bits/stdc++.h>
using namespace std;
const int MAX = 100 * 1000;
vector<int> badj[MAX + 10];
vector<int> adj[MAX + 10];
bool mrk2[MAX + 10];
bool mrk[MAX + 10];
int f[MAX + 10];
int n, m;
void read();
void dfs1(int);
void dfs2(int);
int main() {
  read();
  for (int i = 0; i < n; i++)
    if (f[i] == 1 && !mrk[i]) dfs1(i);
  for (int i = 0; i < n; i++)
    if (f[i] == 2 && !mrk2[i]) dfs2(i);
  for (int i = 0; i < n; i++) cout << (mrk[i] && mrk2[i]) << endl;
  return 0;
}
void read() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> f[i];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    badj[v].push_back(u);
  }
}
void dfs1(int v) {
  mrk[v] = true;
  for (int i = 0; i < ((int)adj[v].size()); i++)
    if (!mrk[adj[v][i]]) dfs1(adj[v][i]);
}
void dfs2(int v) {
  mrk2[v] = true;
  if (f[v] == 1) return;
  for (int i = 0; i < ((int)badj[v].size()); i++)
    if (!mrk2[badj[v][i]]) dfs2(badj[v][i]);
}
