#include <bits/stdc++.h>
using namespace std;
const int MAX = 100 * 1000 + 10;
vector<int> adj[2][MAX + 10];
int st[MAX + 10];
bool mrk[2][MAX + 10];
int n, m;
int g;
void dfs(int v) {
  mrk[g][v] = true;
  for (int i = 0; i < (int)adj[g][v].size(); i++) {
    if (st[adj[g][v][i]] != 1) {
      if (!mrk[g][adj[g][v][i]]) dfs(adj[g][v][i]);
    } else if (g == 1)
      mrk[g][adj[g][v][i]] = true;
  }
}
void DFS(int on) {
  g = on - 1;
  for (int i = 0; i < n; i++)
    if (!mrk[g][i] && st[i] == on) dfs(i);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> st[i];
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    u--;
    v--;
    adj[0][v].push_back(u);
    adj[1][u].push_back(v);
  }
  DFS(1);
  DFS(2);
  for (int i = 0; i < n; i++) cout << (mrk[0][i] && mrk[1][i]) << endl;
  return 0;
}
