#include <bits/stdc++.h>
using namespace std;
int f[100010], r[2][100010];
vector<int> mat[2][100010];
void DFS(int a, int x) {
  r[x][a] = 1;
  if (x == 1 && f[a] == 1) return;
  for (int i = 0; i < mat[x][a].size(); i++) {
    int b = mat[x][a][i];
    if (!r[x][b]) DFS(b, x);
  }
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> f[i];
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    mat[0][a].push_back(b);
    mat[1][b].push_back(a);
  }
  for (int i = 0; i < n; i++)
    if (!r[0][i] && f[i] == 1 && mat[0][i].size())
      DFS(i, f[i] - 1);
    else if (!r[1][i] && f[i] == 2)
      DFS(i, f[i] - 1);
  for (int i = 0; i < n; i++)
    if (r[0][i] && r[1][i])
      cout << 1 << " ";
    else
      cout << 0 << " ";
  cout << endl;
  return 0;
}
