# Enter your code here. Read input from STDIN. Print output to STDOUT row1 = map(int, raw_input().split(' ')) row2 = map(int, raw_input().split(' ')) row3 = map(int, raw_input().split(' ')) answer = 9999 matrix = [row1[0],row1[1],row1[2], row2[0],row2[1],row2[2], row3[0],row3[1],row3[2]] combos = ['816357492', '618753294', '492357816', '294753618', '834159672', '438951276', '672159834', '276951438'] for c in combos: t = map(int, c) result = 0 for i in range(9): #print "result=>%d ... matrix[i]=>%d ... t[i]=>%d" % (result, matrix[i], t[i]) result = result + abs(matrix[i] - t[i]) #print "-----> %d" % (result) if result < answer: answer = result print answer