import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { int[][] s = new int[3][3]; int ms[][] = { { 8, 1, 6 }, { 3, 5, 7 }, { 4, 9, 2 } }; Scanner sc = new Scanner(System.in); for(int i=0;i<3;i++) for(int j=0;j<3;j++) s[i][j] = sc.nextInt(); int dif1=0, dif2=0, dif3=0, dif4=0, dif5=0, dif6=0, dif7=0, dif8=0; for(int i=0;i<3;i++) for(int j=0;j<3;j++) { dif1+=Math.abs(s[i][j]-ms[i][j]); dif2+=Math.abs(s[i][j]-ms[2-i][j]); dif3+=Math.abs(s[i][j]-ms[i][2-j]); dif4+=Math.abs(s[i][j]-ms[2-i][2-j]); dif5+=Math.abs(s[i][j]-ms[j][i]); dif6+=Math.abs(s[i][j]-ms[2-j][i]); dif7+=Math.abs(s[i][j]-ms[j][2-i]); dif8+=Math.abs(s[i][j]-ms[2-j][2-i]); } System.out.println(Math.min(Math.min(Math.min(dif1,dif2),Math.min(dif3,dif4)), Math.min(Math.min(dif5,dif6),Math.min(dif7,dif8)))); } }