square =[] for i in range(3): square.extend([int(square_temp) for square_temp in input().strip().split(' ')]) cnt = 0 a = [] a.append([4,9,2,3,5,7,8,1,6]) a.append([2,9,4,7,5,3,6,1,8]) a.append([8,1,6,3,5,7,4,9,2]) a.append([6,1,8,7,5,3,2,9,4]) a.append([4,3,8,9,5,1,2,7,6]) a.append([8,3,4,1,5,9,6,7,2]) a.append([2,7,6,9,5,1,4,3,8]) a.append([6,7,2,1,5,9,8,3,4]) b = [0] * 8 for i in range(9): for j in range(8): b[j] += abs(square[i] - a[j][i]) print(min(b))