#include <bits/stdc++.h>
using namespace std;
const size_t N = 100 + 5;
const size_t V = N * (N + 5);
struct Edge {
  int to, cap, cost, rev;
  Edge() { to = cap = cost = rev = 0; }
  Edge(int to, int cap, int cost, int rev)
      : to(to), cap(cap), cost(cost), rev(rev) {}
};
vector<Edge> g[V];
int n, idg[N][N], idp[N], a[N][N], cnt = 1;
int dist[V], prv[V], pre[V];
bool inq[V];
void add_edge(int u, int v, int cap, int cost) {
  g[u].push_back(Edge(v, cap, cost, g[v].size()));
  g[v].push_back(Edge(u, 0, -cost, g[u].size() - 1));
}
bool update(int& dist, int val) {
  if (!~dist || dist > val) {
    dist = val;
    return true;
  }
  return false;
}
bool spfa(int s, int t) {
  memset(dist, -1, sizeof dist);
  queue<int> que;
  dist[s] = 0;
  que.push(s);
  inq[s] = true;
  for (int v, i, u; !que.empty();) {
    v = que.front();
    que.pop();
    inq[v] = false;
    for (i = 0; i < g[v].size(); ++i) {
      u = g[v][i].to;
      if (g[v][i].cap && update(dist[u], dist[v] + g[v][i].cost)) {
        prv[u] = v;
        pre[u] = i;
        if (!inq[u]) {
          que.push(u);
          inq[u] = true;
        }
      }
    }
  }
  return ~dist[t];
}
int min_cost_flow(int s, int t) {
  int res = 0, f, v;
  while (spfa(s, t)) {
    f = 1e9;
    for (v = t; v != s; v = prv[v]) {
      f = min(f, g[prv[v]][pre[v]].cap);
    }
    res += f * dist[t];
    for (v = t; v != s; v = prv[v]) {
      Edge& e = g[prv[v]][pre[v]];
      e.cap -= f;
      g[v][e.rev].cap += f;
    }
  }
  return res;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i != j) {
        a[i][j] = 2;
      }
    }
  }
  int s = 0, t, en;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      add_edge(s, cnt, 1, 0);
      idg[i][j] = idg[j][i] = cnt++;
    }
  }
  en = cnt - 1;
  for (int i = 1; i <= n; ++i) {
    idp[i] = cnt++;
  }
  t = cnt++;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0, _ = n - 1; j <= _; ++j) {
      add_edge(idp[i], t, 1, j);
    }
  }
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x][y] = 1;
    a[y][x] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      scanf("%d", a[i] + j);
      if (a[i][j]) {
        add_edge(idg[i][j], idp[i], 1, 0);
      }
    }
  }
  min_cost_flow(s, t);
  for (int i = 1, v = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j, ++v) {
      for (int k = 0; k < g[v].size(); ++k) {
        if (!g[v][k].cap) {
          int x = g[v][k].to - en;
          int y = (x == i ? j : i);
          a[x][y] = 1;
          a[y][x] = 0;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      printf("%d", a[i][j]);
    }
    putchar('\n');
  }
  return 0;
}
