#include <bits/stdc++.h>
using namespace std;
void bfs(int n, const vector<int> *G, const vector<int> &start,
         const vector<int> &ban, bool *vis) {
  bool ban_table[100000] = {};
  for (int i = 0; i < (ban.size()); i++) {
    int u = ban[i];
    ban_table[u] = true;
  }
  queue<pair<int, bool> > Q;
  for (int i = 0; i < (start.size()); i++) {
    int u = start[i];
    vis[u] = true;
    Q.push(make_pair(u, true));
  }
  while (!Q.empty()) {
    int u = Q.front().first;
    bool b = Q.front().second;
    Q.pop();
    if (!b && ban_table[u]) continue;
    for (int i = 0; i < (G[u].size()); i++) {
      int v = G[u][i];
      if (!vis[v]) {
        vis[v] = true;
        Q.push(make_pair(v, false));
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> start, end;
  for (int u = 0; u < (n); u++) {
    int action;
    scanf("%d", &action);
    if (action == 1) start.push_back(u);
    if (action == 2) end.push_back(u);
  }
  static vector<int> G[100000], G_rev[100000];
  for (int i = 0; i < (m); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    G[u].push_back(v);
    G_rev[v].push_back(u);
  }
  static bool vis[100000], vis_rev[100000];
  bfs(n, G, start, start, vis);
  bfs(n, G_rev, end, start, vis_rev);
  for (int u = 0; u < (n); u++) printf("%d\n", vis[u] && vis_rev[u] ? 1 : 0);
  return 0;
}
