#include <bits/stdc++.h>
using namespace std;
int a[6][6];
int main() {
  int m = 0;
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      cin >> a[i][j];
      if (a[i][j] == 1) {
        m = abs(3 - i) + abs(3 - j);
      }
    }
  }
  cout << m << endl;
  return 0;
}
