#include <bits/stdc++.h>
using namespace std;
int main() {
  int m[5][5], c, r;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> m[i][j];
    }
  }
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      if (m[i][j] == 1) {
        r = i + 1;
        c = j + 1;
        goto x;
      }
    }
  }
x:
  int z = 0;
  z = abs(c - 3) + abs(r - 3);
  cout << z << "\n";
}
