#include <bits/stdc++.h>
using namespace std;
int mas[5], i, j, c, a, b, k = 1;
int main() {
  for (i = 1; i <= 25; i++) {
    cin >> c;
    if (c == 1) b = i;
  }
  while (b > 5) {
    b -= 5;
    k++;
  }
  if (b > 3)
    b -= 3;
  else
    b = 3 - b;
  if (k > 3)
    k -= 3;
  else
    k = 3 - k;
  cout << k + b << endl;
}
