#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
typename T::value_type arr_sum(const T& v, int n) {
  typename T::value_type sum = 0;
  for (int i = (0); i < (n); ++i) sum += v[i];
  return sum;
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
vector<int> v;
vector<vector<int>> in;
vector<vector<int>> out;
vector<int> used1;
vector<int> used2;
vector<int> cl;
void dfs1(int t) {
  used1[t] = 1;
  for (auto i : out[t]) {
    if (!used1[i]) {
      dfs1(i);
    }
  }
}
void dfs2(int t) {
  used2[t] = 1;
  if (v[t] == 1) {
    return;
  }
  for (auto i : in[t]) {
    if (!used2[i]) {
      dfs2(i);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  v.resize(n);
  in.resize(n);
  out.resize(n);
  used1.resize(n);
  used2.resize(n);
  for (int i = 0; i < (n); ++i) cin >> v[i];
  ;
  for (int i = (0); i < (m); ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    in[b].push_back(a);
    out[a].push_back(b);
  }
  for (int i = (0); i < (n); ++i) {
    if (!used1[i] && v[i] == 1) {
      dfs1(i);
    }
  }
  for (int i = (0); i < (n); ++i) {
    if (!used2[i] && v[i] == 2) {
      dfs2(i);
    }
  }
  for (int i = (0); i < (n); ++i) {
    cout << (used1[i] & used2[i]) << "\n";
  }
}
