#include <bits/stdc++.h>
int main() {
  for (int i = 0; i != 25; ++i) {
    int n;
    std::cin >> n;
    if (n == 1) {
      std::cout << std::abs(2 - i / 5) + std::abs(2 - i % 5) << std::endl;
      break;
    }
  }
}
