#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[5][5], i, j, one[2], nr = 0, nc = 0;
  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      cin >> a[i][j];
      if (a[i][j] == 1) {
        one[0] = i;
        one[1] = j;
      }
    }
  }
  if (one[0] == 0 || one[0] == 4) {
    nr = 2;
  } else if (one[0] == 1 || one[0] == 3) {
    nr = 1;
  }
  if (one[1] == 0 || one[1] == 4) {
    nc = 2;
  } else if (one[1] == 1 || one[1] == 3) {
    nc = 1;
  }
  cout << nr + nc;
  return 0;
}
