#include <bits/stdc++.h>
using namespace std;
int main() {
  int m[6][6];
  int i, j, x, y;
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      cin >> m[i][j];
      if (m[i][j] == 1) {
        x = i;
        y = j;
      }
    }
  }
  int pos = 0;
  if (x == 3)
    pos = 0;
  else if (x < 3) {
    for (i = x; i < 3; i++) {
      pos++;
    }
  } else {
    for (i = x; i > 3; i--) {
      pos++;
    }
  }
  if (y == 3) {
    if (x == 3) pos = 0;
  } else if (y < 3) {
    for (i = y; i < 3; i++) {
      pos++;
    }
  } else {
    for (i = y; i > 3; i--) {
      pos++;
    }
  }
  cout << pos;
}
