#include <bits/stdc++.h>
using namespace std;
vector<int> adjListF[100010], adjListR[100010];
int N, M;
int actions[100010];
bool vis[100010];
bool flag1[100010], flag2[100010];
void dfs(int u, vector<int> adjList[], bool flag[]) {
  vis[u] = flag[u] = true;
  for (int i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (vis[v] == true) continue;
    if (actions[v] == 1) {
      flag[v] = true;
      continue;
    }
    dfs(v, adjList, flag);
  }
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) scanf("%d", &actions[i]);
  for (int i = 0; i < M; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    adjListF[u].push_back(v);
    adjListR[v].push_back(u);
  }
  for (int i = 0; i < N; i++)
    if (vis[i] == false && actions[i] == 2) dfs(i, adjListR, flag2);
  for (int i = 0; i < N; i++) vis[i] = false;
  for (int i = 0; i < N; i++)
    if (vis[i] == false && actions[i] == 1) dfs(i, adjListF, flag1);
  for (int i = 0; i < N; i++) cout << (flag1[i] && flag2[i] ? 1 : 0) << endl;
  return 0;
}
