import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner inp=new Scanner(System.in); int cost=0,wri=0,wci=0,ws=0,sum=0,i=0,j=0; int ms[][]=new int[3][3]; for(i=0;i<3;i++){ sum=0; for(j=0;j<3;j++){ ms[i][j]=inp.nextInt(); sum=sum+ms[i][j] ; } if(sum!=15){ wri=i; ws=sum; } } for(i=0;i<3;i++){ sum=0; for(j=0;j<3;j++){ sum=sum+ms[j][i] ; } if(sum!=15){ wci=i; } } cost=(int)Math.abs((15-(ws-(ms[wri][wci])))-ms[wri][wci]); System.out.println(cost) ; } }