#include <bits/stdc++.h>
using namespace std;
const int M = 100100;
int n, m, t[M];
vector<int> f[M], b[M];
bool v[M], w[M];
void fr(int x) {
  if (!v[x]) {
    v[x] = 1;
    for (int i = f[x].size(); i-- > 0;) fr(f[x][i]);
  }
}
void bk(int y) {
  if (!w[y]) {
    w[y] = 1;
    if (t[y] != 1)
      for (int i = b[y].size(); i-- > 0;) bk(b[y][i]);
  }
}
int main(void) {
  scanf("%d %d", &n, &m);
  for (int x = 1; x <= n; ++x) scanf("%d", &t[x]);
  for (int i = 0, x, y; i < m && 2 == scanf("%d %d", &x, &y); ++i)
    f[x].push_back(y), b[y].push_back(x);
  for (int x = 1; x <= n; ++x)
    if (1 == t[x] && !v[x]) fr(x);
  for (int y = 1; y <= n; ++y)
    if (2 == t[y] && !w[y]) bk(y);
  for (int x = 1; x <= n; ++x) printf("%d\n", v[x] && w[x] ? 1 : 0);
}
