#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

double R = 6378.1;
double r = R;
struct Point
{  
    double x, y, z;
    Point(){};
    Point(double x, double y, double z):x(x),y(y), z(z){};

    Point operator -(Point p){
        return Point(x-p.x, y-p.y, z-p.z);
    }
    double getDist2(){
        return x*x+y*y+z*z;
    }

    void print(){
        printf("(%lf, %lf, %lf)\n", x, y, z);
    }
};

Point getPoint(double ang1, double ang2){
    return Point(R*cos(ang1)*cos(ang2), R*cos(ang1)*sin(ang2), R*sin(ang1));
}

double getAng(double d){
    return d*PI/180;
}

int main(){
    double a, b, c, d;
    while(cin>>a>>b>>c>>d){
        if(a == -1 && b==-1 && c ==-1 && d == -1) break;
        Point p1 = getPoint(getAng(a), getAng(b)), p2 = getPoint(getAng(c), getAng(d));
        //p1.print();
        //p2.print();
        double co = (2*r*r-(p1-p2).getDist2())/2/r/r;
        double e = acos(co);

        cout<<(int)(r*e+0.5)<<endl;
    }
}