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