#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[5][5];
  int a, b, count = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 1) {
        a = i;
        b = j;
      }
    }
  }
  if (a < 2) {
    count += (2 - a);
  }
  if (a > 2) {
    count += (a - 2);
  }
  if (b < 2) {
    count += (2 - b);
  }
  if (b > 2) {
    count += (b - 2);
  }
  cout << count;
  return 0;
}
