Amit has been practicing "pattern printing" problems a lot. To test his ability Jitendra gives him a problem.He tells him to print the given matrix in the diagonal fashion.

Note: Direction of the diagonal is from the upper-right corner to lower-left corner.See sample test cases for more clarification.Imagine you are Amit. Write the code to prove your ability!

Input:

First line contain the values of N and M.

Next N lines contain M space separated numbers.

Output:

Print the given matrix in the diagonal fashion as described.

Constraints:

1 ≤ N,M ≤ 100

0 ≤ element of matrix ≤100

SAMPLE INPUT
3 3
1 2 3 
5 6 7
0 1 2

SAMPLE OUTPUT
1 
2 5 
3 6 0 
7 1 
2
n,m=map(int,raw_input().split())
lst=[]
for _ in range(n):
	lst.append(raw_input().split())
x=min(n,m)
for i in range(x):
	r=i
	c=0
	for j in range(i+1):
		print lst[c][r],
		c+=1
		r-=1
	print ''
if x!=m:
	c=x
	k=x
	while c!=m:
		k=c
		for i in range(n):
			print lst[i][k],
			k-=1
		print ''
		c+=1
			
for i in range(1,n):
	s=m-1
	j=i
	while j<n and s>=0:
		
    
		try:print lst[j][s],
		except:print j,s,"inlast",n
		s-=1
		j+=1
	print''