#include <bits/stdc++.h>
using namespace std;
int countbit(int n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); }
int lowbit(int n) { return (n ^ (n - 1)) & n; }
int n, m;
int f[100010];
vector<int> edge[100010], edge2[100010];
char v[100010], w[100010];
void dfs(int x) {
  v[x] = 1;
  for (int i = 0; i < edge[x].size(); ++i) {
    int y = edge[x][i];
    if (!v[y]) dfs(y);
  }
}
void dfs2(int x) {
  w[x] = 1;
  if (f[x] == 1) return;
  for (int i = 0; i < edge2[x].size(); ++i) {
    int y = edge2[x][i];
    if (!w[y]) dfs2(y);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", &f[i]);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    edge[a].push_back(b);
    edge2[b].push_back(a);
  }
  for (int i = 0; i < n; ++i)
    if (f[i] == 1) dfs(i);
  for (int i = 0; i < n; ++i)
    if (f[i] == 2) dfs2(i);
  for (int i = 0; i < n; ++i) printf("%d\n", v[i] & w[i]);
  return 0;
}
