#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[6][6], c = 0, i, j, d;
  for (i = 1; i < 6; i++) {
    for (j = 1; j < 6; j++) cin >> a[i][j];
  }
  for (i = 1; i < 6; i++) {
    for (j = 1; j < 6; j++) {
      if (a[i][j] == 1) {
        if (i == 1 || i == 5)
          c = 2;
        else if (i == 2 || i == 4)
          c = 1;
        else
          c = 0;
      }
      if (a[i][j] == 1) {
        if (j == 1 || j == 5)
          d = 2;
        else if (j == 2 || j == 4)
          d = 1;
        else
          d = 0;
        cout << (c + d);
        break;
      }
    }
  }
}
