#include <bits/stdc++.h>
using namespace std;
int main() {
  int matrix[24];
  int n, p, k = 0, ok = 0;
  for (int i = 0; i <= 24 && ok == 0; i++) {
    cin >> n;
    matrix[i] = n;
    if (matrix[i] != 0) {
      p = i;
      ok = 1;
    }
  }
  if (p == 12)
    cout << 0;
  else if (p == 7 || p == 11 || p == 17 || p == 13)
    cout << 1;
  else if (p == 10 || p == 16 || p == 22 || p == 18 || p == 14 || p == 8 ||
           p == 2 || p == 6)
    cout << 2;
  else if (p == 1 || p == 5 || p == 15 || p == 21 || p == 23 || p == 19 ||
           p == 9 || p == 3)
    cout << 3;
  else
    cout << 4;
  return 0;
}
