#include <bits/stdc++.h>
using namespace std;
vector<int> E[100010], I[100010];
int n, m;
int V[100010];
int entrada[100010];
int saida[100010];
void dfse(int v) {
  if (entrada[v] != -1) return;
  if (V[v] == 1) return;
  entrada[v] = 1;
  for (int i = 0; i < E[v].size(); i++) {
    int viz = E[v][i];
    dfse(viz);
  }
}
void dfss(int v) {
  if (saida[v] != -1) return;
  if (V[v] == 1) return;
  saida[v] = 1;
  for (int i = 0; i < I[v].size(); i++) {
    int viz = I[v][i];
    dfss(viz);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) E[i].clear(), I[i].clear();
  for (int i = 0; i < n; i++) scanf("%d", &V[i]);
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    x--, y--;
    E[x].push_back(y);
    I[y].push_back(x);
  }
  memset(entrada, -1, sizeof entrada);
  memset(saida, -1, sizeof saida);
  for (int i = 0; i < n; i++) {
    if (V[i] == 1) {
      entrada[i] = 1;
      for (int j = 0; j < E[i].size(); j++) dfse(E[i][j]);
    } else if (V[i] == 2) {
      saida[i] = 1;
      for (int j = 0; j < I[i].size(); j++) dfss(I[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (V[i] == 0) {
      if (entrada[i] == 1 && saida[i] == 1)
        printf("1\n");
      else
        printf("0\n");
    } else if (V[i] == 1) {
      int flag = 0;
      for (int j = 0; j < E[i].size(); j++)
        if (saida[E[i][j]] == 1) flag = 1;
      printf("%d\n", flag);
    } else {
      int flag = 0;
      for (int j = 0; j < I[i].size(); j++)
        if (entrada[I[i][j]] == 1) flag = 1;
      printf("%d\n", flag);
    }
  }
  return 0;
}
