#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = ((1 << 31) - 1);
const long long LLINF = (((1LL << 63) - 1LL));
const double eps = 1e-9;
const double PI = 3.14159265358979323846;
const string PROBLEM_NAME = "task";
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> f(n);
  for (int i = 0; i < n; ++i) scanf("%d", &f[i]);
  vector<vector<int> > al(n);
  vector<vector<int> > tal(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    al[a].push_back(b);
    tal[b].push_back(a);
  }
  queue<int> Q1;
  queue<int> Q2;
  vector<bool> used1(n, 0);
  vector<bool> used2(n, 0);
  for (int i = 0; i < n; ++i) {
    if (f[i] == 1) {
      Q1.push(i);
      used1[i] = 1;
    }
    if (f[i] == 2) {
      Q2.push(i);
      used2[i] = 1;
    }
  }
  while (!Q1.empty()) {
    int v = Q1.front();
    Q1.pop();
    for (int i = 0; i < al[v].size(); ++i) {
      int v2 = al[v][i];
      if (f[v2] == 1 || used1[v2]) continue;
      used1[v2] = 1;
      Q1.push(v2);
    }
  }
  while (!Q2.empty()) {
    int v = Q2.front();
    Q2.pop();
    for (int i = 0; i < tal[v].size(); ++i) {
      int v2 = tal[v][i];
      if (used2[v2]) continue;
      used2[v2] = 1;
      if (f[v2] == 1) {
        continue;
      }
      Q2.push(v2);
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%d ", int(used1[i] && used2[i]));
  }
  return 0;
}
