#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 100;
int n, m, a[Maxn];
bool mark[2][Maxn];
vector<int> nei[2][Maxn];
void dfs(int x, int v) {
  for (int i = 0; i < (int)nei[x][v].size(); i++) {
    int u = nei[x][v][i];
    if (!mark[x][u]) {
      mark[x][u] = true;
      if (x == 0 || a[u] != 1) dfs(x, u);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0, u, v; i < m; i++) {
    cin >> u >> v;
    nei[0][u - 1].push_back(v - 1);
    nei[1][v - 1].push_back(u - 1);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 1 && !mark[0][i])
      mark[0][i] = true, dfs(0, i);
    else if (a[i] == 2 && !mark[1][i])
      mark[1][i] = true, dfs(1, i);
  }
  for (int i = 0; i < n; i++) {
    if (mark[0][i] && mark[1][i])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}
