#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int one_i = 0, one_j = 0;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) {
      int a;
      cin >> a;
      if (a == 1) {
        one_i = i;
        one_j = j;
      }
    }
  cout << abs(one_i - 2) + abs(one_j - 2);
  return 0;
}
