#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int N = 1 << 17;
int n, m, id[N], res[N], T;
vector<int> v, g;
vector<vector<int> > ar, ed;
bool visited[N];
void dfs(int x) {
  T++;
  if (visited[x] || (id[x] == 1 && T != 1)) return;
  visited[x] = 1;
  res[x]++;
  for (int i = 0; i < (int)ar[x].size(); i++) {
    dfs(ar[x][i]);
  }
}
void dfs2(int x) {
  if (visited[x]) return;
  visited[x] = 1;
  res[x]++;
  if (id[x] == 1) return;
  for (int i = 0; i < (int)ed[x].size(); i++) {
    dfs2(ed[x][i]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &id[i]);
    if (id[i] == 1) v.push_back(i);
    if (id[i] == 2) g.push_back(i);
  }
  ar.resize(n);
  ed.resize(n);
  for (int i = 0; i < m; i++) {
    int from, to;
    scanf("%d%d", &from, &to);
    from--, to--;
    ar[from].push_back(to);
    ed[to].push_back(from);
  }
  int L = (int)v.size();
  for (int i = 0; i < L; i++) {
    T = 0;
    dfs(v[i]);
  }
  memset(visited, 0, sizeof(visited));
  L = (int)g.size();
  for (int i = 0; i < L; i++) {
    dfs2(g[i]);
  }
  for (int i = 0; i < n; i++) {
    if (res[i] == 2)
      printf("1 ");
    else
      printf("0 ");
  }
  return 0;
}
