#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#define pow2(a) ((a)*(a))
#define inf (1<<29)
using namespace std;

const double r = 6378.1;

struct Point3
{
  double x,y,z;
  Point3(double x=inf,double y=inf,double z=inf):x(x),y(y),z(z){}
};

Point3 getPoint3(double a,double b)
{//see P.133
  return Point3(r*sin(a)*cos(b),r*sin(a)*sin(b),r*cos(a));
}

double getArg(double a,double b,double c)
{
  return acos((b*b+c*c-a*a)/(2.0*b*c));
}

int main()
{
 
  double a,b,c,d;
  while(true)
    {
      cin >> a >> b >> c >> d;
      if(a == -1 && b == -1 && c == -1 && d == -1)break;
      a = 90 - a;
      a = a*M_PI/180.0;
      b = b*M_PI/180.0;
      c = 90 - c;
      c = c*M_PI/180.0;
      d = d*M_PI/180.0;
      Point3 p1,p2;
      p1 = getPoint3(a,b);
      p2 = getPoint3(c,d);

      double dist = sqrt(pow2(p1.x-p2.x)+pow2(p1.y-p2.y)+pow2(p1.z-p2.z));
      double arg = getArg(dist,r,r);

      cout << (int)round(r * arg) << endl;

    }
  return 0;
}