#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, count = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> n;
      if (n == 1) {
        count = abs(2 - i) + abs(2 - j);
        cout << count << endl;
        return 0;
      }
    }
  }
  cout << count << endl;
  return 0;
}
