#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
const double PI = acos(-1);

int main(){
    while(1){
        double a,b,c,d;
        cin >> a >> b >> c >> d;
        if(b == -1) break;
        a *= PI/180;
        b *= PI/180;
        c *= PI/180;
        d *= PI/180;

        double r = 6378.1;
        double xa,ya,za, xb,yb,zb;
        xa = cos(b) *r*cos(a); xb = cos(d) *r*cos(c);
        ya = sin(b) *r*cos(a); yb = sin(d) *r*cos(c);
        za = r *sin(a); zb = r *sin(c);
        double s = sqrt((xa-xb)*(xa-xb) +(ya-yb)*(ya-yb) +(za-zb)*(za-zb));
        double t = sqrt(xa*xa +ya*ya +za*za);
        double u = sqrt(xb*xb +yb*yb +zb*zb);
        double theta = acos((t*t +u*u -s*s)/(2*t*u));
        cout << fixed << setprecision(10);
        cout << (int)round(r*abs(theta)) << endl;
    }
    return 0;
}
