#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;

struct point3d {
	double x;
	double y;
	double z;
};

point3d polar_to_point3d(double latitude_rad, double longitude_rad, double r)
{
	point3d p;

	p.x = r * cos(longitude_rad) * cos(latitude_rad);
	p.y = r * sin(longitude_rad) * cos(latitude_rad);
	p.z = r * sin(latitude_rad);

	return p;
}

double get_distance(const point3d& p1, const point3d& p2)
{
	return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2) + pow(p1.z - p2.z, 2));
}

double deg_to_rad(double deg) {
	return M_PI * deg / 180.0;
}

int main()
{
	static const double r = 6378.1;
	double a, b, c, d;

	while (cin >> a >> b >> c >> d) {
		if (a == -1 && b == -1 && c == -1 && d == -1) {
			break;
		}

		point3d p1 = polar_to_point3d(deg_to_rad(a), deg_to_rad(b), r);
		point3d p2 = polar_to_point3d(deg_to_rad(c), deg_to_rad(d), r);

		double dist = get_distance(p1, p2);
		double cos_theta = 1 - dist * dist / (2 * r * r);
		double l = r * acos(cos_theta);

		cout << lround(l) << endl;
	}
}