# Enter your code here. Read input from STDIN. Print output to STDOUT a=map(int,raw_input().strip().split(" ")) M=[a] for j in range(1,3): a=map(int,raw_input().strip().split(" ")) M.append(a) #Now M is a 3x3 matrix magicm={} #magicm is a dictionary magicm[1]=[[4,9,2],[3,5,7],[8,1,6]] magicm[2]=[[8,3,4],[1,5,9],[6,7,2]] magicm[3]=[[6,1,8],[7,5,3],[2,9,4]] magicm[4]=[[2,7,6],[9,5,1],[4,3,8]] magicm[5]=zip(*magicm[1]) magicm[6]=zip(*magicm[2]) magicm[7]=zip(*magicm[3]) magicm[8]=zip(*magicm[4]) def subtractM(m,M): return map(lambda i: map(lambda x,y: x-y, m[i],M[i]),xrange(len(m))) totdiff=[] for k in range(1,9): m=magicm[k] difm=subtractM(m,M) absdiff=map(lambda i: map(lambda x: abs(x),difm[i]),xrange(len(difm))) sumd=sum(absdiff[0])+sum(absdiff[1])+sum(absdiff[2]) totdiff.append(sumd) print min(totdiff)