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