#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

struct P3
{
    double x, y, z;
    P3() : x(0), y(0), z(0){}
    P3(double x, double y, double z) : x(x), y(y), z(z) {}
    P3 operator-(const P3 &p) const
	{
		return P3(x-p.x, y-p.y, z-p.z);
    }
};

double norm(const P3 &p)
{
    return(p.x * p.x + p.y * p.y + p.z * p.z);
}

void solve()
{
	double nt1, nt2, et1, et2;
	const double R = 6378.1;
    while(cin >> nt1 >> et1 >> nt2 >> et2)
	{
		if(nt1 == -1 && nt2 == -1 && et1 == -1 && et2 == -1) 
		{
			break;
		}
		nt1 = nt1 / 360 * 2 * M_PI;
		et1 = et1 / 360 * 2 * M_PI;
		nt2 = nt2 / 360 * 2 * M_PI;
		et2 = et2 / 360 * 2 * M_PI;
		
		P3 p1 = P3(cos(nt1) * cos(et1), cos(nt1) * sin(et1), sin(nt1));
		P3 p2 = P3(cos(nt2) * cos(et2), cos(nt2) * sin(et2), sin(nt2));
		double d = norm(p1 - p2);
		double th = acos((2 - d) / 2);
		cout << (int)(R * th + 0.5) << endl;
    }
}

int main()
{
	solve();
	return(0);
}