#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int n = 5;
int xi, xj;
int mi = 3, mj = 3;
int total_moves;
void citire() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 1) {
        xi = i;
        xj = j;
      }
    }
}
int moves() {
  if (xi != mi) {
    total_moves += (abs(xi - mi));
    if (xj != mj) total_moves += (abs(xj - mj));
  } else if (xj != mj)
    total_moves += (abs(xj - mj));
  return total_moves;
}
int main() {
  citire();
  cout << moves();
  return 0;
}
