#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
const int INF = 0x3f3f3f3f;
struct edge {
  int to, cap, cost, rev;
  edge() {}
  edge(int _to, int _cap, int _cost, int _rev)
      : to(_to), cap(_cap), cost(_cost), rev(_rev) {}
};
int V, H[N], dis[N], pV[N], pE[N];
vector<edge> G[N];
void init(int n) {
  V = n;
  for (int i = (0); i <= (V); ++i) G[i].clear();
}
void add(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));
}
int mincost(int s, int t, int f, int& flow) {
  int res = 0;
  fill(H, H + 1 + V, 0);
  while (f) {
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   greater<pair<int, int> > >
        q;
    fill(dis, dis + 1 + V, INF);
    dis[s] = 0;
    q.push({0, s});
    while (!q.empty()) {
      pair<int, int> now = q.top();
      q.pop();
      int u = now.second;
      if (dis[u] < now.first) continue;
      for (int i = 0; i < (G[u].size()); ++i) {
        edge& e = G[u][i];
        if (e.cap > 0 && dis[e.to] > dis[u] + e.cost + H[u] - H[e.to]) {
          dis[e.to] = dis[u] + e.cost + H[u] - H[e.to];
          pV[e.to] = u;
          pE[e.to] = i;
          q.push({dis[e.to], e.to});
        }
      }
    }
    if (dis[t] == INF) break;
    for (int i = (0); i <= (V); ++i) H[i] += dis[i];
    int d = f;
    for (int v = t; v != s; v = pV[v]) d = min(d, G[pV[v]][pE[v]].cap);
    f -= d;
    flow += d;
    res += d * H[t];
    for (int v = t; v != s; v = pV[v]) {
      edge& e = G[pV[v]][pE[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
int n, m, g[55][55], id[55][55], q[55];
int main() {
  cin >> n >> m;
  memset(g, -1, sizeof(g));
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    cin >> u >> v, g[u][v] = 1, g[v][u] = 0;
    ++q[u];
  }
  int cnt = n;
  for (int i = (1); i <= (n); ++i)
    for (int j = (i + 1); j <= (n); ++j)
      if (g[i][j] == -1) id[i][j] = ++cnt;
  int S = cnt + 1, T = S + 1;
  init(T + 1);
  for (int i = (1); i <= (n); ++i)
    for (int j = (i + 1); j <= (n); ++j)
      if (g[i][j] == -1) {
        add(id[i][j], i, 1, 0);
        add(id[i][j], j, 1, 0);
      }
  for (int i = (1); i <= (n); ++i)
    for (int j = (i + 1); j <= (n); ++j)
      if (g[i][j] == -1) {
        add(S, id[i][j], 1, 0);
      }
  int C = 0, ans = 0;
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (n - 1 - q[i]); ++j)
      add(i, T, 1, 2 * q[i] + j * j - (j - 1) * (j - 1));
    C += q[i] * q[i];
  }
  C += mincost(S, T, INF, ans);
  C -= n * (n - 1) / 2;
  C /= 2;
  for (int i = (1); i <= (n); ++i)
    for (int j = (i + 1); j <= (n); ++j)
      if (g[i][j] == -1) {
        for (edge& e : G[id[i][j]]) {
          if ((e.to == i || e.to == j) && !e.cap) {
            g[i][j] = (e.to == i);
            g[j][i] = (e.to == j);
          }
        }
      }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (n); ++j) {
      if (i == j)
        cout << "0";
      else
        cout << g[i][j];
    }
    cout << '\n';
  }
}
