#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[25], i, x = 0, b = 0;
  for (i = 0; i < 25; i++) {
    cin >> a[i];
  }
  for (i = 0; i < 25; i++) {
    if (a[i] != 0) {
      x = i + 1;
    }
  }
  if (x % 5 == 0) {
    b = 5;
    x = x / 5;
  } else {
    b = x % 5;
    x = x / 5 + 1;
  }
  if (x > 3) {
    x = x - 3;
  } else {
    x = 3 - x;
  }
  if (b > 3) {
    b = b - 3;
  } else {
    b = 3 - b;
  }
  cout << x + b << endl;
}
