#include <bits/stdc++.h>
int main() {
  int aij;
  int swapTime = 0;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++) {
      scanf("%d", &aij);
      if (aij == 1) {
        if (i >= 3)
          swapTime += i - 3;
        else
          swapTime += 3 - i;
        if (j >= 3)
          swapTime += j - 3;
        else
          swapTime += 3 - j;
        printf("%d\n", swapTime);
        return 0;
      }
    }
}
