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