#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int r = 0, c = 0, a[6][6], o = 0, re, ce;
  for (r = 1; r < 6; r++) {
    for (c = 1; c < 6; c++) {
      cin >> a[r][c];
      if (a[r][c] == 1) {
        re = r;
        ce = c;
      }
    }
  }
  o = abs(re - 3) + abs(ce - 3);
  cout << o;
  return 0;
}
