#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int m = 0;
  int n = 0;
  for (int i = 0; i < 5; i++) {
    bool found = false;
    for (int j = 0; j < 5; j++) {
      int x;
      cin >> x;
      if (x == 1) {
        found = true;
        m = i + 1;
        n = j + 1;
        break;
      }
    }
    if (found) break;
  }
  n = abs(3 - n);
  m = abs(3 - m);
  cout << m + n;
}
