#include <bits/stdc++.h>
int arr[30][30];
int main() {
  int i, j, I, J;
  for (i = 1; i <= 5; i++)
    for (j = 1; j <= 5; j++) {
      scanf("%d", &arr[i][j]);
      if (arr[i][j] == 1) {
        I = i;
        J = j;
      }
    }
  printf("%d", abs(3 - I) + abs(3 - J));
  return 0;
}
