You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:

  1. Swap two neighboring matrix rows, that is, rows with indexes i and i + 1 for some integer i (1 ≤ i < 5). 
  2. Swap two neighboring matrix columns, that is, columns with indexes j and j + 1 for some integer j (1 ≤ j < 5). 



You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.

Input

The input consists of five lines, each line contains five integers: the j-th integer in the i-th line of the input represents the element of the matrix that is located on the intersection of the i-th row and the j-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.

Output

Print a single integer — the minimum number of moves needed to make the matrix beautiful.

Examples

Input

0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0


Output

3


Input

0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0


Output

1




#intialize empty list to save input list rows into
r = []
#we need a pointer for when we find the one within the row
one_id = 0
#we need a pointer for which row we are in
row_of_one = 0

# we are taking in 5 row lists as input
for i in range(5):
	#print(f"i = : {i}")
	
	#need a list to hold each row so we can search it later
	row = [int(i) for i in input().split()][:5]
	# add each row into the list of row lists
	r.append(row)
	#print (f"our list so far: {r}")
	
	#traverse the list row we just took in to search for the one
	for k in range(len(row)):
		#print(f"k = : {k}")
		if row[k] == 1:
			row_of_one = i
			#print(f"row of one found: {i}")
			one_id = k
			#print(f"id of one found: {k}")
#just need to know how many rows and columns the 1 is from 2,2 now!
hor_moves = abs(one_id - 2)
vert_moves = abs(row_of_one - 2)
print (hor_moves + vert_moves)




#we have the position of the one now
#now to manipulate the array to put the one in the middle
#let's do rows first

#if the 1 isn't in the middle row, swap it's row with the middle row
'''
assignment is just to calculate how many moves, but this actually moves it there! woohoo extra credit
if row_of_one != 2:
	#swap the rows
	r[2], r[row_of_one] = r[row_of_one], r[2]
	print(f"r[2]: {r[2]}")
	print (f"r[row_of_one]: {r[row_of_one]}")
	print (r)
if one_id != 2:
	r[2][2] = 1
	r[2][one_id] = 0

'''















