#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <limits>
using namespace std;
typedef long long ll;

const double pi = atan(1) * 4;

struct Pt {
	double x, y, z;
	Pt(double r, double a, double b){
		// aが上下
		// bが回転
		if(a < 0)a += 360;

		a = (a / 360) * 2 * pi;
		b = (b / 360) * 2 * pi;

		y = r * sin(a);

		double t = r * cos(a);

		x = t * cos(b);
		z = t * sin(b);
	}
};

double getDist(Pt a, Pt b){
	double dx = a.x - b.x;
	double dy = a.y - b.y;
	double dz = a.z - b.z;

	return sqrt(dx * dx + dy * dy + dz * dz);
}

const double r = 6378.1;
const double k = 2 * r * r;

int main(){
	double a, b, c, d;

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

		Pt A(r, a, b), B(r, c, d);

		double D = getDist(A, B);

		double theta = acos((D * D - k) / -k);
		double dist = r * theta;

		int dist_a = (int)(dist + 0.5);
		int dist_b = (int)(2 * pi * r - dist + 0.5);

		cout << min(dist_a, dist_b) << endl;

	}
	return 0;
}