#include <bits/stdc++.h>
int main(void) {
  int i, j, a[6][6], s = 0, t = 0;
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      scanf("%d", &a[i][j]);
      if (a[i][j] == 1) {
        s = i;
        t = j;
      }
    }
  }
  printf("%d\n", abs(s - 3) + abs(t - 3));
  return 0;
}
