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