#include <bits/stdc++.h>
using namespace std;
int a[100005];
bool vis1[100005], vis2[100005];
vector<int> e1[100005], e2[100005];
queue<int> q1, q2;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e1[x].push_back(y);
    e2[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      vis1[i] = 1;
      q1.push(i);
    }
  }
  while (!q1.empty()) {
    int now = q1.front();
    q1.pop();
    for (int i = 0; i < e1[now].size(); i++) {
      int v = e1[now][i];
      if (a[v] == 1 || vis1[v]) continue;
      vis1[v] = 1;
      q1.push(v);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 2) {
      vis2[i] = 1;
      q2.push(i);
    }
  }
  while (!q2.empty()) {
    int now = q2.front();
    q2.pop();
    for (int i = 0; i < e2[now].size(); i++) {
      int v = e2[now][i];
      if (a[v] == 1) vis2[v] = 1;
      if (a[v] == 1 || vis2[v]) continue;
      vis2[v] = 1;
      q2.push(v);
    }
  }
  for (int i = 1; i <= n; i++)
    if (vis1[i] && vis2[i])
      printf("1\n");
    else
      printf("0\n");
  return 0;
}
