#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int i = 1;
  int j;
  while (i <= 5) {
    j = 1;
    while (j <= 5) {
      cin >> n;
      if (n == 1) break;
      j++;
    }
    if (n == 1) break;
    i++;
  }
  if (i == 3)
    i = 0;
  else if (i < 3) {
    i = 3 - i;
  } else if (i > 3)
    i = i - 3;
  if (j == 3)
    j = 0;
  else if (j < 3)
    j = 3 - j;
  else if (j > 3)
    j = j - 3;
  cout << i + j;
}
