#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
int a[100500];
bool res[100500];
bool vis[100500];
bool one[100500];
bool two[100500];
vector<vector<int> > l;
vector<vector<int> > rev;
queue<int> q;
void f1(int v) {
  vis[v] = true;
  one[v] = true;
  for (int i = 0; i < l[v].size(); i++)
    if (!vis[l[v][i]]) f1(l[v][i]);
}
void f2(int v) {
  vis[v] = true;
  two[v] = true;
  for (int i = 0; i < rev[v].size(); i++)
    if (!vis[rev[v][i]]) {
      if (a[rev[v][i]] == 1)
        two[rev[v][i]] = true;
      else
        f2(rev[v][i]);
    }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  l.resize(n + 1);
  rev.resize(n + 1);
  int first, second;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &first, &second);
    l[first].push_back(second);
    rev[second].push_back(first);
  }
  memset(vis, false, sizeof(vis));
  memset(one, false, sizeof(one));
  for (int i = 1; i <= n; i++)
    if (a[i] == 1 && !vis[i]) f1(i);
  memset(vis, false, sizeof(vis));
  memset(two, false, sizeof(two));
  for (int i = 1; i <= n; i++)
    if (a[i] == 2 && !vis[i]) f2(i);
  for (int i = 1; i <= n; i++)
    if (one[i] && two[i])
      printf("1\n");
    else
      printf("0\n");
  return 0;
}
