#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[500][500], i, j, cnt = 0;
  ;
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      if (a[1][1] == 1 or a[5][1] or a[1][5] or a[5][5]) {
        cnt = 4;
      } else if (a[1][2] == 1 or a[1][4] == 1 or a[5][2] == 1 or a[5][4] == 1 or
                 a[2][1] == 1 or a[4][1] == 1 or a[2][5] == 1 or a[4][5] == 1) {
        cnt = 3;
      } else if (a[2][2] == 1 or a[2][4] == 1 or a[3][1] == 1 or a[3][5] == 1 or
                 a[4][2] == 1 or a[4][4] == 1 or a[1][3] == 1 or a[5][3] == 1) {
        cnt = 2;
      } else if (a[2][3] == 1 or a[3][2] == 1 or a[3][4] == 1 or a[4][3] == 1) {
        cnt = 1;
      } else if (a[3][3] == 1) {
        cnt = 0;
      }
    }
  }
  cout << cnt;
  return 0;
}
