#include <bits/stdc++.h>
using namespace std;
int main() {
  int matrix[5][5];
  int cora = 0;
  int corb = 0;
  for (int i = 0; i < 5; i++) {
    for (int k = 0; k < 5; k++) {
      cin >> matrix[i][k];
      if (matrix[i][k] == 1) {
        cora = i + 1;
        corb = k + 1;
      }
    }
  }
  cora -= 3;
  corb -= 3;
  cout << abs(cora) + abs(corb);
  return 0;
}
