#include <bits/stdc++.h>
using namespace std;
int main() {
  int x = -1, y = -1;
  for (int i = 0; i < 5; ++i) {
    int val = 0;
    for (int j = 0; j < 5; ++j) {
      cin >> val;
      if (val == 1) {
        x = i;
        y = j;
      }
    }
  }
  int ox = 0;
  if (x > 2)
    ox = x - 2;
  else
    ox = 2 - x;
  if (y == 2)
    cout << 0 + ox;
  else if (y > 2)
    cout << y - 2 + ox;
  else
    cout << 2 - y + ox;
  cout << endl;
  return 0;
}
