#include <bits/stdc++.h>
const double eps = 1e-9;
const int int_inf = 2000000000;
const long long i64_inf = 1000000000000000000LL;
const double pi = acos(-1.0);
using namespace std;
vector<int> g[100500];
vector<int> gt[100500];
int first[100500];
bool used1[100500];
bool used2[100500];
int n, m;
void dfs1(int v) {
  used1[v] = 1;
  if (first[v] == 1) return;
  for (int i = 0; i < (int)(int)g[v].size(); i++) {
    int to = g[v][i];
    if (used1[to]) continue;
    dfs1(to);
  }
}
void dfs2(int v) {
  used2[v] = 1;
  for (int i = 0; i < (int)(int)gt[v].size(); i++) {
    int to = gt[v][i];
    if (used2[to]) continue;
    dfs2(to);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)n; i++) scanf("%d", &first[i + 1]);
  memset(used1, 0, sizeof(used1));
  memset(used2, 0, sizeof(used2));
  for (int i = 0; i < (int)m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[b].push_back(a);
    gt[a].push_back(b);
  }
  for (int i = 0; i < (int)n; i++)
    if (!used1[i + 1] && first[i + 1] == 2) dfs1(i + 1);
  for (int i = 0; i < (int)n; i++)
    if (!used2[i + 1] && first[i + 1] == 1) dfs2(i + 1);
  for (int i = 0; i < (int)n; i++)
    if (used1[i + 1] && used2[i + 1])
      puts("1");
    else
      puts("0");
  return 0;
}
