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