#include <bits/stdc++.h>
using namespace std;
int n, m, a[100100], ans1[100100], ans2[100100];
bool mark[2][100100];
vector<int> adj[2][100100];
void dfs(int x, int id) {
  mark[id][x] = true;
  if (a[x] == 1 && id == 1) return;
  for (int i = 0; i < adj[id][x].size(); i++) {
    int v = adj[id][x][i];
    if (!mark[id][v]) dfs(v, id);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[0][x].push_back(y);
    adj[1][y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    if (!mark[0][i] && a[i] == 1) dfs(i, 0);
  for (int i = 1; i <= n; i++)
    if (!mark[1][i] && a[i] == 2) dfs(i, 1);
  for (int i = 1; i <= n; i++) cout << (mark[0][i] && mark[1][i]) << endl;
  return -0;
}
