#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n, m;
int f[N + 1];
vector<int> g[N + 1][2];
bool ans[N + 1][2];
bool used[N + 1][2];
vector<int> v;
void dfs(int u, int k) {
  v.push_back(u);
  used[u][k] = 1;
  if (f[u] == 2 - k) {
    for (int i = 0; i < v.size(); i++) ans[v[i]][k] = 1;
    v.clear();
  }
  for (int i = 0; i < g[u][k].size(); i++)
    if (!used[g[u][k][i]][k])
      dfs(g[u][k][i], k);
    else if (ans[g[u][k][i]][k]) {
      for (int i = 0; i < v.size(); i++) ans[v[i]][k] = 1;
      v.clear();
    }
}
int main() {
  scanf("%i%i", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%i", &f[i]);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%i%i", &a, &b);
    if (f[b] != 1) {
      g[a][0].push_back(b);
      g[b][1].push_back(a);
    }
  }
  for (int k = 0; k < 2; k++)
    for (int i = 1; i <= n; i++)
      if (f[i] == 1 + k) {
        v.clear();
        dfs(i, k);
      }
  for (int i = 1; i <= n; i++) printf("%i\n", (ans[i][0] && ans[i][1] ? 1 : 0));
  return 0;
}
