import sys input = sys.stdin.readline from operator import itemgetter N,M=map(int,input().split()) A=[list(map(int,input().split())) for i in range(N)] B=[] for i in range(N): X=A[i] Y=[[X[j],j+1] for j in range(N)] Y.sort(key=itemgetter(0),reverse=True) B.append(Y) ANS=[] for tests in range(M): X=[]*N USE=[0]*(N+1) for i in range(N): for j in range(N): w,ind=B[i][j] if w>0 and USE[ind]==0: X.append(ind) USE[ind]=1 B[i][j][0]-=1 break B[i].sort(key=itemgetter(0),reverse=True) if len(X)==N: ANS.append(X) else: print(-1) exit() for i in range(N): for j in range(N): if B[i][j][0]>0: print(-1) exit() for ans in ANS: print(*ans)