#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
const int INF = 2000000000;
const int mod = 1000000007;
const int N = 100000000;
const int base = 10;
vector<int> read(string s) {
  vector<int> a;
  for (int i = (int)s.length(); i > 0; i -= 1)
    if (i < 1)
      a.push_back(atoi(s.substr(0, i).c_str()));
    else
      a.push_back(atoi(s.substr(i - 1, 1).c_str()));
  return a;
}
vector<int> add(vector<int> a, vector<int> b) {
  int carry = 0;
  for (size_t i = 0; i < max(a.size(), b.size()) || carry; ++i) {
    if (i == a.size()) a.push_back(0);
    a[i] += carry + (i < b.size() ? b[i] : 0);
    carry = a[i] >= base;
    if (carry) a[i] -= base;
  }
  return a;
}
vector<int> mul(vector<int> a, int b) {
  int carry = 0;
  for (size_t i = 0; i < a.size() || carry; ++i) {
    if (i == a.size()) a.push_back(0);
    long long cur = carry + a[i] * 1ll * b;
    a[i] = int(cur % base);
    carry = int(cur / base);
  }
  while (a.size() > 1 && a.back() == 0) a.pop_back();
  return a;
}
vector<int> c;
vector<int> a[100005], b[100005];
vector<bool> f;
vector<bool> f1;
int main() {
  vector<int> queue;
  int n, x, y, m;
  cin >> n >> m;
  for (int(i) = (0); (i) < (n); (i)++) {
    cin >> x;
    c.push_back(x);
  }
  for (int(i) = (0); (i) < (m); (i)++) {
    cin >> x >> y;
    x--;
    y--;
    a[x].push_back(y);
    b[y].push_back(x);
  }
  for (int(i) = (0); (i) < (c.size()); (i)++)
    if (c[i] == 1) {
      queue.push_back(i);
      f.push_back(true);
    } else {
      f.push_back(false);
    }
  for (int(i) = (0); (i) < (queue.size()); (i)++) {
    for (int(j) = (0); (j) < (a[queue[i]].size()); (j)++) {
      if (f[a[queue[i]][j]]) continue;
      queue.push_back(a[queue[i]][j]);
      f[a[queue[i]][j]] = true;
    }
  }
  queue.clear();
  for (int(i) = (0); (i) < (c.size()); (i)++)
    if (c[i] == 2) {
      queue.push_back(i);
      f1.push_back(true);
    } else {
      f1.push_back(false);
    }
  for (int(i) = (0); (i) < (queue.size()); (i)++) {
    for (int(j) = (0); (j) < (b[queue[i]].size()); (j)++) {
      if (f1[b[queue[i]][j]]) continue;
      f1[b[queue[i]][j]] = true;
      if (c[b[queue[i]][j]] == 1) continue;
      queue.push_back(b[queue[i]][j]);
    }
  }
  for (int(i) = (0); (i) < (n); (i)++)
    if (f[i] && f1[i]) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  return 0;
}
