# Enter your code here. Read input from STDIN. Print output to STDOUT s1 = map(int,raw_input().split()) s2 = map(int,raw_input().split()) s3 = map(int,raw_input().split()) s=s1+s2+s3 magicsquarelst = [[2,9,4,7,5,3,6,1,8],[2,7,6,9,5,1,4,3,8],[4,9,2,3,5,7,8,1,6],[4,3,8,9,5,1,2,7,6],[6,7,2,1,5,9,8,3,4],[6,1,8,7,5,3,2,9,4],[8,3,4,1,5,9,6,7,2],[8,1,6,3,5,7,4,9,2]] total = 100 for item in magicsquarelst: res = reduce(lambda a,b:a+b,map(lambda (x,y):abs(x-y),zip(item,s))) if res < total: total = res print total