#include <bits/stdc++.h>
using namespace std;
long long powerf(long long a, long long b, long long c) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % c;
    }
    b = b >> 1;
    a = (a * a) % c;
  }
  return ans;
}
set<long long> s1, s2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int TEST = 0;
  int t = 1;
  for (int tt = 1; tt <= t; tt++) {
    int a, b, x;
    for (int i = 1; i < 6; i++) {
      for (int j = 1; j < 6; j++) {
        cin >> x;
        if (x == 1) {
          a = i;
          b = j;
          goto th;
        }
      }
    }
  th:
    cout << abs(3 - a) + abs(3 - b) << "\n";
  }
}
