#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, x, perfect_row = 3, perfect_col = 3, arry[5][5], row = 0, col = 0;
  int static moves = 0;
  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      cin >> x;
      arry[i][j] = x;
      if (x == 1) {
        row = i + 1;
        col = j + 1;
        moves = abs(perfect_row - row) + abs(perfect_col - col);
      }
    }
  }
  cout << moves;
  return 0;
}
