#include <bits/stdc++.h>
using namespace std;
const long long int N = 100005;
vector<long long int> adj[N], iadj[N];
long long int f[N];
bool mark1[N], mark2[N];
void dfs1(long long int x) {
  mark1[x] = 1;
  for (auto i : adj[x])
    if (!mark1[i]) dfs1(i);
}
void dfs2(long long int x) {
  mark2[x] = 1;
  if (f[x] == 1) return;
  for (auto i : iadj[x])
    if (!mark2[i]) dfs2(i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) cin >> f[i];
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    iadj[y].push_back(x);
  }
  for (long long int i = 1; i <= n; i++) {
    if (!mark1[i] && f[i] == 1) dfs1(i);
  }
  for (long long int i = 1; i <= n; i++) {
    if (!mark2[i] && f[i] == 2) dfs2(i);
  }
  for (long long int i = 1; i <= n; i++)
    if (mark1[i] && mark2[i])
      cout << 1 << '\n';
    else
      cout << 0 << '\n';
}
