#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct Dinic {
  struct Edge {
    int v, rev, cap, cot;
  };
  vector<Edge> G[maxn];
  int dis[maxn], cur[maxn], vis[maxn], n, sp, tp;
  void init(int nn) {
    n = nn;
    for (int i = 1; i <= n; ++i) G[i].clear();
  }
  void add(int u, int v, int cap, int cot) {
    G[u].push_back({v, ((int)G[v].size()), cap, cot});
    G[v].push_back({u, ((int)G[u].size()) - 1, 0, -cot});
  }
  int bfs() {
    queue<int> q;
    for (int i = 1; i <= n; ++i) dis[i] = inf, vis[i] = 0;
    dis[sp] = 0, q.push(sp), vis[sp] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      vis[u] = 0;
      for (auto &e : G[u]) {
        if (e.cap && dis[e.v] > dis[u] + e.cot) {
          dis[e.v] = dis[u] + e.cot;
          if (!vis[e.v]) q.push(e.v), vis[e.v] = 1;
        }
      }
    }
    return dis[tp] != inf;
  }
  int dfs(int u, int flow) {
    if (u == tp || !flow) return flow;
    int ret = 0, tmp;
    vis[u] = 1;
    for (int &i = cur[u]; i < ((int)G[u].size()); ++i) {
      auto &e = G[u][i];
      if (!vis[e.v] && dis[e.v] == dis[u] + e.cot &&
          (tmp = dfs(e.v, min(e.cap, flow - ret)))) {
        ret += tmp, e.cap -= tmp, G[e.v][e.rev].cap += tmp;
        if (ret == flow) {
          vis[u] = 0;
          return ret;
        }
      }
    }
    if (!ret) vis[u] = 1;
    return ret;
  }
  pair<int, int> solve(int s, int t) {
    sp = s, tp = t;
    int mf = 0, mc = 0;
    while (bfs()) {
      for (int i = 1; i <= n; ++i) cur[i] = 0;
      int tmp = dfs(sp, inf);
      mf += tmp, mc += tmp * dis[tp];
    }
    return {mf, mc};
  }
} dinic;
int id[55][55], G[55][55], in[55];
int n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  memset(G, -1, sizeof G);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    ++in[v];
    G[u][v] = 1, G[v][u] = 0;
  }
  int S = n * (n - 1) + n + 1, T = S + 1;
  dinic.init(T);
  int tot = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < i; ++j) {
      id[i][j] = ++tot;
      if (G[i][j] != -1) continue;
      dinic.add(S, id[i][j], 1, 0);
      dinic.add(id[i][j], n * (n - 1) + i, 1, 0);
      dinic.add(id[i][j], n * (n - 1) + j, 1, 0);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = in[i]; j < n - 1; ++j) {
      dinic.add(n * (n - 1) + i, T, 1, j);
    }
  }
  dinic.solve(S, T);
  for (int i = 1; i <= tot; ++i) {
    if (!((int)dinic.G[i].size())) continue;
    auto &e1 = dinic.G[i][1];
    auto &e2 = dinic.G[i][2];
    int v1 = e1.v - n * (n - 1);
    int v2 = e2.v - n * (n - 1);
    G[v1][v2] = e1.cap;
    G[v2][v1] = G[v1][v2] ^ 1;
  }
  for (int i = 1; i <= n; ++i) G[i][i] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) cout << G[i][j];
    cout << "\n";
  }
  return 0;
}
