#include <bits/stdc++.h>
using namespace std;
int main() {
  int ar[6][6], i, j, res;
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      cin >> ar[i][j];
      if (ar[i][j] == 1) {
        res = abs(3 - i) + abs(3 - j);
        cout << res;
        exit(0);
      }
    }
  }
}
