#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double L = 6378.1;
const double PI = acos(-1.0);

void solve(double n0, double e0, double& x, double& y, double& z)
{
    double n = n0 / 180 * PI;
    double e = e0 / 180 * PI;

    x = cos(n) * cos(e);
    y = cos(n) * sin(e);
    z = sin(n);
}

int main()
{
    for(;;){
        double a, b, c, d;
        cin >> a >> b >> c >> d;
        if(b < -0.5)
            return 0;

        double x1, y1, z1, x2, y2, z2;
        solve(a, b, x1, y1, z1);
        solve(c, d, x2, y2, z2);

        double dist = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2) + pow(z1-z2, 2));
        double theta = asin(dist / 2) * 2;

        int ret = (int)(L * theta + 0.5);
        cout << ret << endl;
    }
}