#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int MAXN = 2e9 + 10;
int n, m;
vector<int> f[N][2];
int sign[N];
bool v[2][N];
bool ans[N];
void init() {
  int x, y;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &sign[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    f[x][0].push_back(y);
    f[y][1].push_back(x);
  }
  memset(v, 0, sizeof(v));
  memset(ans, 0, sizeof(ans));
}
void dfs(int x, bool s) {
  if (v[s][x]) return;
  v[s][x] = true;
  if (s && sign[x] == 1) return;
  for (int i = 0; i < f[x][s].size(); i++) dfs(f[x][s][i], s);
}
void work() {
  for (int i = 1; i <= n; i++)
    if (sign[i] != 0) dfs(i, sign[i] - 1);
  for (int i = 1; i <= n; i++) {
    ans[i] = (v[0][i] & v[1][i]);
    printf("%d\n", ans[i]);
  }
}
int main() {
  init();
  work();
  return 0;
}
