#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[10][10];
  int sx, sy;
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      cin >> a[i][j];
      if (a[i][j] != 0) {
        sx = i;
        sy = j;
      }
    }
  }
  int sum = fabs(sx - 3) + fabs(sy - 3);
  cout << sum << endl;
  return 0;
}
