#include <bits/stdc++.h>
using namespace std;
const double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230;
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
void sol() {
  int arr[5][5];
  int res;
  for (int x = 0; x < 5; x++) {
    for (int y = 0; y < 5; y++) {
      cin >> arr[x][y];
      if (arr[x][y]) res = abs(x - 2) + abs(y - 2);
    }
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  sol();
}
