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