#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool Up(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool Down(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
inline int getus() {
  int tmp, c;
  while (tmp = fgetc(stdin), tmp < '0' || tmp > '9')
    ;
  tmp -= '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return tmp;
}
inline int getint() {
  int tmp, c, flag;
  while (flag = fgetc(stdin), flag != '-' && (flag < '0' || flag > '9'))
    ;
  if (flag == '-')
    tmp = 0;
  else
    tmp = flag - '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return flag == '-' ? -tmp : tmp;
}
int N, M, State[100022], vis[100022];
int Left[100022], Right[100022];
vector<int> fir[100022], op[100022];
queue<int> q;
void Work() {
  int x, y;
  memset(vis, 0, sizeof(vis));
  memset(Left, 0, sizeof(Left));
  memset(Right, 0, sizeof(Right));
  for (int i = (1); i <= (N); ++i)
    if (State[i] == 1) {
      q.push(i);
      vis[i] = 1;
    }
  while (!q.empty()) {
    x = q.front();
    q.pop();
    Left[x] = 1;
    for (__typeof(fir[x].begin()) e = fir[x].begin(); e != fir[x].end(); ++e)
      if (!vis[y = *e]) {
        if (State[y] == 1) continue;
        vis[y] = 1;
        q.push(y);
      }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = (1); i <= (N); ++i)
    if (State[i] == 2) {
      q.push(i);
      vis[i] = 1;
    }
  while (!q.empty()) {
    x = q.front();
    q.pop();
    Right[x] = 1;
    for (__typeof(op[x].begin()) e = op[x].begin(); e != op[x].end(); ++e)
      if (!vis[y = *e]) {
        if (State[y] == 1) {
          Right[y] = 1;
          continue;
        }
        vis[y] = 1;
        q.push(y);
      }
  }
  for (int i = (1); i <= (N); ++i) printf("%d\n", Left[i] & Right[i]);
}
void Init() {
  memset(vis, 0, sizeof(vis));
  int a, b;
  N = getus();
  M = getus();
  for (int i = (1); i <= (N); ++i) {
    State[i] = getus();
  }
  for (int i = (1); i <= (M); ++i) {
    a = getus();
    b = getus();
    fir[a].push_back(b);
    op[b].push_back(a);
  }
}
int main() {
  Init();
  Work();
  return 0;
}
