#include <bits/stdc++.h>
using namespace std;
int main() {
  register int i, j;
  int arr[5][5], posi, posj;
  for (i = 0; i < 5; i++)
    for (j = 0; j < 5; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 1) {
        posi = i;
        posj = j;
      }
    }
  cout << abs(posi - 2) + abs(posj - 2) << "\n";
  return 0;
}
