#include <bits/stdc++.h>
using namespace std;
bool mat[6][6];
int row1, column1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int row = 1; row <= 5; row++) {
    for (int column = 1; column <= 5; column++) {
      cin >> mat[row][column];
      if (mat[row][column]) {
        row1 = row;
        column1 = column;
      }
    }
  }
  cout << abs(row1 - 3) + abs(column1 - 3);
  return 0;
}
