#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
int n, m;
int f[maxn];
vector<int> buf1[maxn], buf2[maxn];
bool vis1[maxn] = {}, vis2[maxn] = {};
bool go[maxn] = {};
vector<int> todel;
void bfs(vector<int> *buf, bool *vis, int xx, int t) {
  for (int i = 0; i < (n); ++i)
    if (f[i] == xx && !vis[i]) {
      vis[i] = true;
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (vector<int>::iterator it = (buf[x]).begin(); it != (buf[x]).end();
             ++it)
          if (!vis[*it]) {
            if (f[*it] == t) {
              if (xx == 2) vis[*it] = true;
            } else {
              vis[*it] = true;
              q.push(*it);
            }
          }
      }
    }
}
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); ++i) scanf("%d", f + i);
  for (int i = 0; i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    buf1[a].push_back(b);
    buf2[b].push_back(a);
  }
  bfs(buf1, vis1, 1, 1);
  bfs(buf2, vis2, 2, 1);
  for (int i = 0; i < (n); ++i) printf("%d\n", vis1[i] && vis2[i]);
  return 0;
}
