#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
bool mark[maxn], rmark[maxn];
int a[maxn];
vector<int> v[maxn], rv[maxn];
inline void dfs(int x, int par) {
  if (mark[x]) return;
  if (par != -1 && a[x] == 1) return;
  mark[x] = 1;
  for (int i = 0; i < v[x].size(); i++)
    if (!mark[v[x][i]]) dfs(v[x][i], x);
}
inline void rdfs(int x) {
  if (rmark[x]) return;
  rmark[x] = 1;
  if (a[x] == 1) return;
  for (int i = 0; i < rv[x].size(); i++)
    if (!rmark[rv[x][i]]) rdfs(rv[x][i]);
}
int main() {
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    rv[y].push_back(x);
  }
  for (int i = 0; i < n; i++)
    if (a[i] == 1) dfs(i, -1);
  for (int i = 0; i < n; i++)
    if (a[i] == 2) rdfs(i);
  for (int i = 0; i < n; i++)
    if (mark[i] && rmark[i])
      cout << 1 << "\n";
    else
      cout << 0 << "\n";
}
