#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
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 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;
      Q.push(i);
    }
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    for (int i = 0; i < E1[now].size(); i++) {
      int x = E1[now][i];
      if (a[x] == 1) continue;
      if (vis1[x]) continue;
      vis1[x] = 1;
      Q.push(x);
    }
  }
  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 x = E2[now][i];
      if (a[x] == 1) vis2[x] = 1;
      if (vis2[x]) continue;
      vis2[x] = 1;
      Q.push(x);
    }
  }
  for (int i = 1; i <= n; i++)
    if (vis1[i] && vis2[i])
      printf("1\n");
    else
      printf("0\n");
}
