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) { Scanner in = new Scanner(System.in); int[][] array = new int[3][3]; int[] sums = new int[8]; for(int i = 0; i < 3; i++){ for(int y = 0; y < 3; y++){ array[i][y] = in.nextInt(); } } sums[0] = array[0][0] + array[0][1] + array[0][2]; sums[1] = array[1][0] + array[1][1] + array[1][2]; sums[2] = array[2][0] + array[2][1] + array[2][2]; sums[3] = array[0][0] + array[1][0] + array[2][0]; sums[4] = array[0][1] + array[1][1] + array[2][1]; sums[5] = array[0][2] + array[1][2] + array[2][2]; sums[6] = array[0][0] + array[1][1] + array[2][2]; sums[7] = array[0][2] + array[1][1] + array[2][0]; int max = 0; for(int i = 0; i < 8; i++){ if(sums[i] < 15 && sums[i] > max) max = sums[i]; } System.out.println(15 - max); } }