#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> adj[100004];
vector<int> adjR[100004];
int F[100004];
int D2[100004];
void bfs2() {
  queue<int> q;
  for (int u = 1; u <= N; ++u) {
    D2[u] = -1;
    if (F[u] == 2) {
      q.push(u);
      D2[u] = 0;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (F[u] == 1) continue;
    for (int j = 0; j < adjR[u].size(); ++j) {
      int v = adjR[u][j];
      if (D2[v] < 0) {
        D2[v] = D2[u] + 1;
        q.push(v);
      }
    }
  }
}
int D1[100004];
void bfs1() {
  queue<int> q;
  for (int u = 1; u <= N; ++u) {
    D1[u] = -1;
    if (F[u] == 1) {
      q.push(u);
      D1[u] = 0;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int j = 0; j < adj[u].size(); ++j) {
      int v = adj[u][j];
      if (D1[v] < 0) {
        D1[v] = D1[u] + 1;
        q.push(v);
      }
    }
  }
}
int main(int argc, char* argv[]) {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; ++i) scanf("%d", F + i);
  for (int m = 0; m < M; ++m) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adjR[v].push_back(u);
  }
  bfs1();
  bfs2();
  for (int u = 1; u <= N; ++u) {
    puts(D1[u] >= 0 && D2[u] >= 0 ? "1" : "0");
  }
  return 0;
}
