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