#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
const int SIZE = 1 << 17;
int n, m;
char oper[SIZE];
vector<int> nbr[SIZE], anti[SIZE];
bool fromdef[SIZE];
bool touse[SIZE];
bool used[SIZE];
void DFS1(int u) {
  fromdef[u] = true;
  used[u] = true;
  for (int i = 0; i < nbr[u].size(); i++) {
    int v = nbr[u][i];
    if (used[v]) continue;
    DFS1(v);
  }
}
void DFS2(int u) {
  touse[u] = true;
  used[u] = true;
  if (oper[u] == 1) return;
  for (int i = 0; i < anti[u].size(); i++) {
    int v = anti[u][i];
    if (used[v]) continue;
    DFS2(v);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    oper[i] = t;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    nbr[a].push_back(b);
    anti[b].push_back(a);
  }
  memset(used, 0, sizeof(used));
  for (int i = 0; i < n; i++)
    if (oper[i] == 1)
      if (!used[i]) DFS1(i);
  memset(used, 0, sizeof(used));
  for (int i = 0; i < n; i++)
    if (oper[i] == 2)
      if (!used[i]) DFS2(i);
  for (int i = 0; i < n; i++) printf("%d ", int(fromdef[i] && touse[i]));
  printf("\n");
  return 0;
}
