#include <bits/stdc++.h>
using namespace std;
int n, m, f[100005] = {0}, ans[100005] = {0}, b[100005] = {0}, a1[100005] = {0};
vector<int> p1[100005];
vector<int> p2[100005];
void dfs1(int now) {
  b[now] = 1;
  for (int i = 0; i < p1[now].size(); i++) {
    int x = p1[now][i];
    if (b[x] > 0 || a1[x] == 1) continue;
    a1[x] = 1;
    dfs1(x);
  }
  b[now] = 0;
}
void dfs2(int now) {
  b[now] = 1;
  for (int i = 0; i < p2[now].size(); i++) {
    int x = p2[now][i];
    if (b[x] > 0 || ans[x] == 1) continue;
    ans[x] = 1;
    if (f[x] != 1) dfs2(x);
  }
  b[now] = 0;
}
int main() {
  int i, j, h;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &f[i]);
  while (m--) {
    scanf("%d%d", &i, &j);
    p1[i].push_back(j);
    p2[j].push_back(i);
  }
  for (i = 1; i <= n; i++)
    if (f[i] == 1) a1[i] = 1, dfs1(i);
  for (i = 1; i <= n; i++)
    if (f[i] == 2) ans[i] = 1, dfs2(i);
  for (i = 1; i <= n; i++) printf("%d\n", (ans[i] + a1[i]) / 2);
  return 0;
}
