#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[5][5];
  for (int r = 0; r < 5; r++) {
    for (int c = 0; c < 5; c++) {
      cin >> arr[r][c];
    }
  }
  int xco, yco;
  for (int r = 0; r < 5; r++) {
    for (int c = 0; c < 5; c++) {
      if (arr[r][c] != 0) {
        xco = c;
        yco = r;
      }
    }
  }
  int sum = 0;
  if (xco >= 2) {
    sum = sum + xco - 2;
  } else if (xco < 2) {
    sum = sum + 2 - xco;
  }
  if (yco >= 2) {
    sum = sum + yco - 2;
  } else if (yco < 2) {
    sum = sum + 2 - yco;
  }
  cout << sum << endl;
  return 0;
}
