#include <iostream>
#include <cmath>
using namespace std;
 
int main()
{
    int arr[5][5];
    // entring the array
    for (int i =0 ; i < 5; i++)
    {
        for(int j=0; j < 5; j++)
        {
            cin >> arr[i][j];
        }
    }
    int x =0;
    int y =0;
    
    // finding the cordinates of the one
    for (int i =0 ; i < 5; i++)
    {
        for(int j=0; j < 5; j++)
        {
            if (arr[i][j] == 1)
            {
                x =i;
                y =j;
            }
        }
    }
    cout << (abs(x-2) + abs(y-2));
}