#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
vector<int> edge1[maxn];
vector<int> edge2[maxn];
int vis1[maxn], vis2[maxn];
long long n, m, ans;
long long a[maxn], b[maxn];
queue<int> q;
int main() {
  scanf("%lld %lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    edge1[x].push_back(y);
    edge2[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 < edge1[now].size(); i++) {
      int x = edge1[now][i];
      if (a[x] == 1) {
        continue;
      }
      if (vis1[x] == 1) {
        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 < edge2[now].size(); i++) {
      int x = edge2[now][i];
      if (a[x] == 1) {
        vis2[x] = 1;
      }
      if (vis2[x] == 1) {
        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");
    }
  }
}
