H,W = map(int,input().split()) A = [list(map(int,input().split())) for _ in range(H)] dat = [0] * 10 for h in range(H): for w in range(W): dat[A[h][w]] += 1 now = 0 for h in range(H): for w in range(W): while dat[now] == 0: now += 1 print(now,end = ' ') dat[now] -= 1 print()