#include <bits/stdc++.h>
int to[100010], nxt[100010], lst[100010];
unsigned char f[100010], F[100010];
bool vis[100010];
bool dfs(const int u) {
  if (vis[u]) return true;
  int &i = lst[u], v;
  bool &flg = vis[u];
  flg |= F[u] == 2;
  while (i) {
    v = to[i];
    i = nxt[i];
    if (F[v] == 1) continue;
    flg = flg | dfs(v);
  }
  return flg;
}
int dfn[100010], low[100010], ind;
int q[100010], top, bl[100010], scc;
bool inq[100010];
void tarjan(int u) {
  low[u] = dfn[u] = ++ind;
  q[++top] = u;
  inq[u] = true;
  int i, v;
  for (i = lst[u]; i; i = nxt[i]) {
    v = to[i];
    if (f[v] == 1) continue;
    if (!dfn[v]) {
      tarjan(v);
      if (low[v] < low[u]) low[u] = low[v];
    } else if (inq[v] && dfn[v] < low[u])
      low[u] = dfn[v];
  }
  if (low[u] == dfn[u]) {
    v = 0;
    scc++;
    while (v != u) {
      v = q[top--];
      inq[v] = false;
      bl[v] = scc;
      if (f[v] == 2) F[scc] = 2;
    }
  }
}
int u[100010], v[100010];
char ibuf[2000000], *ip = ibuf;
template <class T>
inline void readi(T &n) {
  while (*ip < 48 || *ip > 57) ip++;
  n = *ip++ - 48;
  while (48 <= *ip && *ip <= 57) n = (n << 1) + (n << 3) + *ip++ - 48;
}
char obuf[400000], *op = obuf;
int main() {
  fread(ibuf, 2000000, 1, stdin);
  int n, m;
  readi(n), readi(m);
  int i;
  for (i = 1; i <= n; i++) readi(f[i]);
  for (i = 1; i <= m; i++) {
    readi(u[i]), readi(v[i]);
    to[i] = v[i];
    nxt[i] = lst[u[i]];
    lst[u[i]] = i;
  }
  for (i = 1; i <= n; i++) {
    if (f[i] == 1)
      scc++, bl[i] = scc, F[scc] = 1;
    else if (!dfn[i])
      tarjan(i);
  }
  memset(lst, 0, sizeof lst);
  for (i = 1; i <= m; i++)
    if (bl[u[i]] != bl[v[i]]) {
      to[i] = bl[v[i]];
      nxt[i] = lst[bl[u[i]]];
      lst[bl[u[i]]] = i;
    }
  for (i = 1; i <= scc; i++)
    if (F[i] == 1) dfs(i);
  for (i = 1; i <= n; i++)
    if (vis[bl[i]])
      *op++ = 49, *op++ = 10;
    else
      *op++ = 48, *op++ = 10;
  fwrite(obuf, op - obuf, 1, stdout);
  return 0;
}
