#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
vector<int> graph[100000];
vector<int> graph_b[100000];
int n, m;
int r[100000];
int v1[100000];
int v2[100000];
void init() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < (n); ++i) scanf("%d", &r[i]);
  for (int i = 0; i < (m); ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    graph[x].push_back(y);
    graph_b[y].push_back(x);
  }
  memset(v1, 0, sizeof(v1));
  memset(v2, 0, sizeof(v2));
}
void run() {
  stack<int> s1;
  for (int i = 0; i < (n); ++i)
    if (r[i] == 1) {
      s1.push(i);
      v1[i] = 1;
    }
  while (!s1.empty()) {
    int my = s1.top();
    s1.pop();
    for (__typeof((graph[my]).begin()) it = (graph[my]).begin();
         it != (graph[my]).end(); ++it) {
      int next = (*it);
      if (!v1[next] && r[next] != 1) {
        s1.push(next);
        v1[next] = 1;
      }
    }
  }
  stack<int> s2;
  for (int i = 0; i < (n); ++i)
    if (r[i] == 2) {
      s2.push(i);
      v2[i] = 1;
    }
  while (!s2.empty()) {
    int my = s2.top();
    s2.pop();
    for (__typeof((graph_b[my]).begin()) it = (graph_b[my]).begin();
         it != (graph_b[my]).end(); ++it) {
      int next = (*it);
      if (!v2[next]) {
        v2[next] = 1;
        if (r[next] != 1) s2.push(next);
      }
    }
  }
  for (int i = 0; i < (n); ++i)
    if (v1[i] && v2[i])
      printf("1\n");
    else
      printf("0\n");
}
int main() {
  init();
  run();
  return 0;
}
