#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const long long inf = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
int n, m, f[N];
bool ans[N], used[N], ans1[N];
vector<int> g[N], gr[N];
void dfs(int v) {
  ans[v] = 1;
  for (auto to : g[v]) {
    if (ans[to]) continue;
    dfs(to);
  }
}
void dfs1(int v) {
  ans1[v] = 1;
  if (f[v] == 1) return;
  for (auto to : gr[v]) {
    if (ans1[to]) continue;
    dfs1(to);
  }
}
inline void boost() {
  ios_base ::sync_with_stdio(NULL);
  cin.tie(NULL), cout.tie(NULL);
}
inline void Solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> f[i];
  for (int i = 1, a, b; i <= m; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    gr[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (f[i] == 1) dfs(i);
  for (int i = 1; i <= n; i++)
    if (f[i] == 2) dfs1(i);
  for (int i = 1; i <= n; i++, cout << '\n') cout << (ans[i] & ans1[i]);
}
int main() {
  int tt = 1;
  while (tt--) {
    Solve();
  }
  return 0;
}
