#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    double a, b, c, d;
    const double r = 6378.1; // 地球の半径

    while (cin >> a >> b >> c >> d) {
        if (a == -1 && b == -1 && c == -1 && d == -1)
            break;
        double x[2], y[2], z[2];
        double theta[2], phi[2];

        phi[0] = b * M_PI / 180.0;
        phi[1] = d * M_PI / 180.0;
        theta[0] = (90.0 - a) * M_PI / 180.0;
        theta[1] = (90.0 - c) * M_PI / 180.0;

        for (int i = 0; i < 2; i++) {
            z[i] = r * cos(theta[i]);
            x[i] = r * sin(theta[i]) * cos(phi[i]);
            y[i] = r * sin(theta[i]) * sin(phi[i]);
        }

        double d[2], inner;

        inner = x[0] * x[1] + y[0] * y[1] + z[0] * z[1];
        for (int i = 0; i < 2; i++) 
            d[i] = sqrt(x[i] * x[i] + y[i] * y[i] + z[i] * z[i]);
        
        cout << (int)(r * acos(inner / d[0] / d[1]) + 0.5) << endl;
    }

    return 0;
}