import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n,m = map(int,input().split()) a = [list(map(int,input().split())) for i in range(n)] flg = 1 for i in range(n): flg &= sum(a[i]) == m for j in range(n): cnt = 0 for i in range(n): cnt += a[i][j] flg &= cnt == m if not flg: print(-1) exit() ans = [[0]*n for i in range(m)] use = [[] for i in range(n+1)] for j in range(n): for i in range(n): for k in range(a[i][j]): use[j + 1].append(i) for i in range(1,n+1): for j in use[i]: for k in range(m): if not ans[k][j] and i not in ans[k]: ans[k][j] = i break for i in ans: print(*i)