#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m, f[N];
bool vis[2][N];
vector<int> edges[2][N];
void dfs0(int x) {
  if (vis[0][x]) return;
  vis[0][x] = 1;
  for (int to : edges[0][x]) {
    if (f[to] != 1) dfs0(to);
  }
}
void dfs1(int x) {
  if (vis[1][x]) return;
  vis[1][x] = 1;
  if (f[x] == 1) return;
  for (int to : edges[1][x]) {
    dfs1(to);
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> f[i];
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    edges[0][u].push_back(v);
    edges[1][v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) {
    if (f[i] == 1) {
      dfs0(i);
    }
    if (f[i] == 2) {
      dfs1(i);
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << (vis[0][i] && vis[1][i]) << ' ';
  }
}
int main() {
  ios::sync_with_stdio(0);
  int T = 1;
  while (T--) {
    solve();
  }
}
