#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[100005];
vector<int> g[100005], rev[100005];
bool vis1[100005], vis2[100005];
bool ans[100005];
void dfs1(int i) {
  vis1[i] = 1;
  for (auto j : g[i]) {
    if (!vis1[j]) dfs1(j);
  }
}
void dfs2(int i) {
  vis2[i] = 1;
  if (f[i] == 1) return;
  for (auto j : rev[i]) {
    if (!vis2[j]) dfs2(j);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  vector<int> st;
  for (int i = 0; i < n; ++i) {
    scanf("%d", f + i + 1);
    if (f[i + 1] == 1) st.push_back(i + 1);
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    rev[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis1[i] && f[i] == 1) dfs1(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis2[i] && f[i] == 2) dfs2(i);
  }
  for (int i = 1; i <= n; ++i) {
    printf("%d\n", vis1[i] && vis2[i]);
  }
  return 0;
}
