#include <bits/stdc++.h>
using namespace std;
long long int lim = 100000 + 10;
int mod = 1000000000 + 7;
int inf = 1000000000;
vector<vector<long long int>> path(lim);
vector<vector<long long int>> rpath(lim);
vector<bool> visited1(lim);
vector<bool> visited2(lim);
vector<long long int> f(lim);
void dfs1(int v) {
  visited1[v] = 1;
  for (int u : path[v]) {
    if (!visited1[u]) {
      dfs1(u);
    }
  }
}
void dfs2(int v) {
  visited2[v] = 1;
  for (int u : rpath[v]) {
    if (!visited2[u]) {
      dfs2(u);
    }
  }
}
int main() {
  int n;
  int m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    path[a].push_back(b);
    if (f[b] != 1) {
      rpath[b].push_back(a);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (f[i] == 1 && !visited1[i]) {
      dfs1(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (f[i] == 2 && !visited2[i]) {
      dfs2(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (visited1[i] && visited2[i]) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }
}
