#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
vector<int> e1[maxn];
vector<int> e2[maxn];
int vis1[maxn];
int vis2[maxn];
int a[maxn];
queue<int> q;
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 u, v;
    scanf("%d%d", &u, &v);
    e1[u].push_back(v);
    e2[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) {
      vis1[i] = 1;
      q.push(i);
    }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < e1[now].size(); i++) {
      int v = e1[now][i];
      if (a[v] == 1) continue;
      if (vis1[v]) continue;
      vis1[v] = 1;
      q.push(v);
    }
  }
  while (!q.empty()) q.pop();
  for (int i = 1; i <= n; i++)
    if (a[i] == 2) {
      vis2[i] = 1;
      q.push(i);
    }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < e2[now].size(); i++) {
      int v = e2[now][i];
      if (a[v] == 1) vis2[v] = 1;
      ;
      if (vis2[v]) continue;
      vis2[v] = 1;
      q.push(v);
    }
  }
  for (int i = 1; i <= n; i++)
    if (vis1[i] && vis2[i])
      printf("1\n");
    else
      printf("0\n");
}
