#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1001;
const int MAXM = 200'001;
const int INF = 1e8;
vector<pair<int, int>> g[MAXN];
vector<int> g2[MAXN];
int vis[MAXN], vis2[MAXM], vis3[MAXN];
int nodes, edges, fok[MAXN], ans[MAXN][MAXN], timer = 2, timer2 = INF, st;
void dfs(int u, int p = -1) {
vis[u] = true;
nodes++;
for (auto [v, idx] : g[u]) {
if (v == p) continue;
if (vis2[idx] == 0) {
vis2[idx] = true;
edges++;
}
if (!vis[v]) {
vis2[idx] = 3;
dfs(v, u);
} else {
st = u;
ans[u][v] = ans[v][u] = 1;
}
}
}
vector<int> cyc;
vector<int> res;
void dfs2(int u, int p = -1) {
vis3[u] = true;
cyc.push_back(u);
for (auto [v, idx] : g[u]) {
if (v == p) continue;
if (v == st) {
res = cyc;
}
if (!res.empty()) return;
if (!vis3[v]) {
dfs2(v, u);
}
if (!res.empty()) return;
}
cyc.pop_back();
}
void dfs3(int u) {
vis3[u] = true;
for (auto [v, idx] : g[u]) {
if (!vis3[v]) {
ans[u][v] = ans[v][u] = timer++;
}
}
for (auto [v, idx] : g[u]) {
if (!vis3[v]) {
dfs3(v);
}
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
ans[i][j] = timer2--;
}
}
for (int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
g[u].emplace_back(v, i);
g[v].emplace_back(u, i);
}
for (int i = 1; i <= n; i++) {
if (g[i].empty()) {
cout << "-1\n";
return 0;
}
}
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
nodes = edges = 0;
st = i;
dfs(i);
if (edges > nodes) {
cout << "-1\n";
return 0;
}
fill(vis3, vis3+MAXN, false);
cyc.clear(); res.clear();
dfs2(st);
if (edges == nodes && res.empty()) {
throw 1;
}
if (edges == nodes - 1 && !res.empty()) throw 1;
if (res.empty()) {
fill(vis3, vis3+MAXN, false);
dfs3(st);
} else {
for (int i = 1; i < res.size(); i++) {
ans[res[i-1]][res[i]] = ans[res[i]][res[i-1]] = timer++;
}
ans[res[0]][res.back()] = ans[res.back()][res[0]] = timer++;
fill(vis3, vis3+MAXN, false);
for (int u : res) vis3[u] = true;
for (int u : res) {
dfs3(u);
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = i+1; j <= n; j++) {
cout << ans[i][j] << " ";
}
cout << "\n";
}
return 0;
}