#include <bits/stdc++.h>
using namespace std;
int main() {
  int data[10][10];
  int i, j;
  int x, y;
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      scanf("%d", &data[i][j]);
      if (data[i][j] == 1) {
        x = i;
        y = j;
      }
    }
  }
  int ans = 0;
  if (x == 2 || x == 4) ans++;
  if (x == 1 || x == 5) ans += 2;
  if (y == 2 || y == 4) ans++;
  if (y == 1 || y == 5) ans += 2;
  printf("%d", ans);
  return 0;
}
