#include <bits/stdc++.h>
using namespace std;
const int Max = 100000 + 10;
vector<int> v[Max];
vector<int> p[Max];
bool mark[Max];
bool mark2[Max];
int arr[Max];
void dfs(int u) {
  mark[u] = 1;
  for (int i = 0; i < v[u].size(); i++)
    if (mark[v[u][i]] == 0) dfs(v[u][i]);
}
void dfs2(int u) {
  mark2[u] = 1;
  if (arr[u] != 1)
    for (int i = 0; i < p[u].size(); i++)
      if (!mark2[p[u][i]]) dfs2(p[u][i]);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i <= m; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    v[tmp1].push_back(tmp2);
    p[tmp2].push_back(tmp1);
  }
  for (int i = 1; i <= n; i++)
    if (arr[i] == 1 && mark[i] == 0) dfs(i);
  for (int i = 1; i <= n; i++)
    if (arr[i] == 2 && mark2[i] == 0) dfs2(i);
  for (int i = 1; i <= n; i++) {
    int k = mark2[i] * mark[i];
    cout << k << endl;
  }
}
