#include <bits/stdc++.h>
using namespace std;
queue<int> q;
vector<int> adjListE[100005];
vector<int> adjListRE[100005];
int visit[100005];
int visit2[100005];
int a[100005];
bool ans[100005];
void addEdge(int u, int v) {
  adjListE[u].push_back(v);
  adjListRE[v].push_back(u);
}
void solve(int n, int m) {
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      visit[i] = true;
      q.push(i);
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto j : adjListE[u]) {
      if (!visit[j]) {
        visit[j] = true;
        q.push(j);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 2) {
      visit2[i] = true;
      q.push(i);
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto j : adjListRE[u]) {
      if (!visit2[j]) {
        visit2[j] = true;
        q.push(j);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (visit2[i] && visit[i])
      cout << 1 << '\n';
    else
      cout << 0 << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long vertices, edges;
  cin >> vertices >> edges;
  for (int i = 1; i <= vertices; i++) cin >> a[i];
  for (int i = 1; i <= edges; i++) {
    long long u, v;
    cin >> u >> v;
    if (a[v] != 1) addEdge(u, v);
  }
  solve(vertices, edges);
  return 0;
}
