#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  int ans = 0;
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j < 6; j++) {
      cin >> c;
      if (c == '1') ans = abs(3 - i) + abs(3 - j);
    }
  }
  cout << ans;
}
