#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long b, long long p) {
  if (p == 0) return 1;
  long long my = bigmod(b, p / 2);
  my *= my;
  my %= 1000000007;
  if (p & 1) my *= b, my %= 1000000007;
  return my;
}
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int pos) { return n = n & ~(1 << pos); }
bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }
vector<int> g[100005], ug[100005];
int visit[100005], wisit[100005];
int n, m, ara[100005];
queue<int> q;
void bfs() {
  while (q.empty() == 0) {
    int u = q.front();
    q.pop();
    if (ara[u] == 1) continue;
    int len = ug[u].size(), i;
    for (i = 0; i < len; i++) {
      int v = ug[u][i];
      if (visit[v] == 0) {
        visit[v] = 1;
        q.push(v);
      }
    }
  }
}
void pfs() {
  while (q.empty() == 0) {
    int u = q.front();
    q.pop();
    int len = g[u].size(), i;
    for (i = 0; i < len; i++) {
      int v = g[u][i];
      if (wisit[v] == 0) {
        wisit[v] = 1;
        q.push(v);
      }
    }
  }
}
int main() {
  int i, j, x, y;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &ara[i]);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    ug[y].push_back(x);
  }
  for (i = 1; i <= n; i++) {
    if (ara[i] == 2) q.push(i), visit[i] = 1;
  }
  bfs();
  for (i = 1; i <= n; i++) {
    if (visit[i] == 1 && ara[i] == 1) q.push(i), wisit[i] = 1;
  }
  pfs();
  for (i = 1; i <= n; i++) {
    if (visit[i] && wisit[i])
      printf("1");
    else
      printf("0");
    printf("\n");
  }
  return 0;
}
