#include <iostream>
#include <vector>
using namespace std;
  
struct Position {
    int x;
    int y;
};

int main() {
    int GroundWidth = 5;
    int GroundHeight = 5;
    Position BoxPosition = {3, 3};
    Position PlayerPosition = {0, 0};
    vector<int>arrint;
    int atom_int, try_time = 0;
    bool foundBox = false;  // 添加一个标记,表示是否已经找到箱子

    // 输入整数并存储到数组中
    while (cin >> atom_int) {
        if (arrint.size() >= GroundWidth * GroundHeight) {
            break;  // 如果输入数量达到了地图大小,结束输入
        }
        arrint.push_back(atom_int) ;
    }
    // 处理数组内容
    for (int i = 0; i < GroundHeight; i++) {
        for (int j = 0; j < GroundWidth; j++) {
            atom_int = arrint[i * GroundWidth + j];
            //cout << atom_int;
            if (atom_int == 1) {
                PlayerPosition.x = j + 1;
                PlayerPosition.y = i + 1;
                //cout << PlayerPosition.x << PlayerPosition.y;
                foundBox = true;
                break;
            }
        }
        if(foundBox){
            break;
        }
    }
    try_time = abs(PlayerPosition.x - BoxPosition.x) + abs(PlayerPosition.y - BoxPosition.y);
    cout << try_time;

    return 0;
}