#include <bits/stdc++.h>
using namespace std;
vector<int> a1[100500], a2[100500];
int f[100500];
int n, m;
int used2[100500], used1[100500];
void dfs1(int v) {
  if (used1[v]) return;
  used1[v] = 1;
  for (int i = 0; i < a1[v].size(); i++)
    if (f[a1[v][i]] != 1) dfs1(a1[v][i]);
}
void dfs2(int v) {
  if (used2[v]) return;
  used2[v] = 1;
  if (f[v] == 1) return;
  for (int i = 0; i < a2[v].size(); i++) dfs2(a2[v][i]);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%d", &f[i]);
  for (int i = 0; i < n; i++) {
    a1[i].clear();
    a2[i].clear();
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    a1[x].push_back(y);
    a2[y].push_back(x);
  }
  memset(used1, 0, sizeof(used1));
  memset(used2, 0, sizeof(used2));
  for (int i = 0; i < n; i++)
    if (!used1[i] && f[i] == 1) dfs1(i);
  for (int i = 0; i < n; i++)
    if (!used2[i] && f[i] == 2) dfs2(i);
  for (int i = 0; i < n; i++) printf("%d\n", used1[i] && used2[i]);
  return 0;
}
