h,w,*a=map(int,open(0).read().split()) a.sort() for i in range(h):print(*a[i*w:(i+1)*w])