#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, cap, flow, cost, index;
  edge(int to, int cap, int flow, int cost, int index)
      : to(to), cap(cap), flow(flow), cost(cost), index(index) {}
};
struct mincostmaxflow {
  int n;
  vector<vector<edge>> g;
  vector<int> potential, prio, prevnode, prevedge, curflow;
  vector<bool> inqueue;
  mincostmaxflow(int n)
      : n(n),
        g(n),
        potential(n),
        prio(n),
        prevnode(n),
        prevedge(n),
        curflow(n),
        inqueue(n, false) {}
  void addedge(int from, int to, int cap, int cost) {
    g[from].push_back(edge(to, cap, 0, cost, g[to].size()));
    g[to].push_back(edge(from, 0, 0, -cost, g[from].size() - 1));
  }
  void bellmanford(int src, vector<int> &dist) {
    fill(dist.begin(), dist.end(), 100000);
    dist[src] = 0;
    queue<int> q;
    inqueue[src] = true;
    q.push(src);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto &e : g[u]) {
        if (e.cap == e.flow) continue;
        int v = e.to;
        int newdist = dist[u] + e.cost;
        if (dist[v] > newdist) {
          dist[v] = newdist;
          if (!inqueue[v]) {
            inqueue[v] = true;
            q.push(v);
          }
        }
      }
    }
  }
  pair<int, int> mincostflow(int src, int dest) {
    bellmanford(src, potential);
    int flow = 0;
    int flowcost = 0;
    while (true) {
      priority_queue<pair<int, int>, vector<pair<int, int>>,
                     greater<pair<int, int>>>
          q;
      fill(prio.begin(), prio.end(), 100000);
      prio[src] = 0;
      q.push({0, src});
      curflow[src] = 100000;
      while (!q.empty()) {
        int d = q.top().first;
        int u = q.top().second;
        q.pop();
        if (prio[u] != d) continue;
        for (int i = 0; i < g[u].size(); i++) {
          edge &e = g[u][i];
          if (e.flow == e.cap) continue;
          int v = e.to;
          int newdist = prio[u] + potential[u] - potential[v] + e.cost;
          if (prio[v] > newdist) {
            prio[v] = newdist;
            q.push({newdist, v});
            curflow[v] = min(curflow[u], e.cap - e.flow);
            prevnode[v] = u;
            prevedge[v] = i;
          }
        }
      }
      if (prio[dest] == 100000) break;
      flow += curflow[dest];
      int temp = curflow[dest];
      for (int i = 0; i < n; i++) potential[i] += prio[i];
      for (int i = dest; i != src; i = prevnode[i]) {
        edge &e = g[prevnode[i]][prevedge[i]];
        e.flow += temp;
        g[e.to][e.index].flow -= temp;
        flowcost += temp * e.cost;
      }
    }
    return {flow, flowcost};
  }
};
int n, m;
int ans[51][51], wins[51];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i == j)
        ans[i][j] = 0;
      else
        ans[i][j] = -1;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    ans[u][v] = 1;
    ans[v][u] = 0;
    wins[u]++;
  }
  int rem = ((n * (n - 1)) / 2 - m);
  mincostmaxflow mcmf(n + rem + 2);
  int match = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (ans[i][j] == -1) {
        mcmf.addedge(match, rem + i, 1, 0);
        mcmf.addedge(match, rem + j, 1, 0);
        match++;
      }
    }
    for (int d = wins[i]; d < n; d++)
      mcmf.addedge(rem + i, rem + n + 1, 1, 2 * d + 1);
  }
  for (int i = 1; i <= rem; i++) mcmf.addedge(0, i, 1, 0);
  mcmf.mincostflow(0, rem + n + 1).first;
  for (int i = 1; i <= rem; i++) {
    int u = -1, v = -1;
    for (int j = 0; j < mcmf.g[i].size(); j++) {
      if (mcmf.g[i][j].to == 0) continue;
      if (mcmf.g[i][j].flow == 1)
        u = mcmf.g[i][j].to - rem;
      else
        v = mcmf.g[i][j].to - rem;
    }
    ans[u][v] = 1;
    ans[v][u] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) printf("%d", ans[i][j]);
    printf("\n");
  }
  return 0;
}
