#include <bits/stdc++.h>
const int N = 1000005;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int matrix[5][5];
  int i1, j1;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> matrix[i][j];
      if (matrix[i][j] == 1) {
        i1 = i;
        j1 = j;
      }
    }
  }
  cout << abs(i1 - 2) + abs(j1 - 2) << endl;
}
