#include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cassert>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

#define X real()
#define Y imag()

typedef complex<double> P;
typedef pair<P, P> L;
typedef vector<P> Pol;

const double INF = 1e40;
const double EPS = 1e-8;
const double PI = acos(-1);

int sig(double r) {return (r < -EPS) ? -1 : (r > EPS) ? 1: 0;}
bool eq(double a, double b) {return abs(a - b) < EPS;}
bool near(P a, P b) {return abs(b - a) < EPS;}

// ツ禿?静?
double dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// ツ外ツ静?
double cross(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// ツ静シツ閉ェツづ個ベツクツトツδ?
P vec(L a) {return a.second - a.first;}

// ツ静シツ閉ェabツづ可妥篠つキツづゥツ点xツづ個暗環置
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(L s, P p) {
  P a = vec(s);
  p -= s.first;
  double cr = cross(a, p);
  if (eq(cr, 0)) {
    if (sig(dot(a, p)) < 0) return BACK;
    if (sig(norm(a) - norm(p)) < 0) return FRONT;
    return ON;
  }
  return (cr > 0) ? LEFT : RIGHT;
}

// ツ角ツ度
double ang(P p) {double theta = arg(p); return sig(theta - 2 * PI) < 0 ? theta : 0;}
double ang(P a, P b) {return acos(dot(a, b) / (abs(a) * abs(b)));}
P plr(double theta) {return polar(1., theta);}
P rot(P p, double theta) { return p * plr(theta);}

// ツ偲仰影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.first + proj(vec(l), p - l.first);}
P refl(L l, P p) {return perp(l, p) * 2. - p;}
 
// ツ古ーツ債キツ板サツ津ィ ツ端ツ点ツづーツ甘慊づ?
bool iLL(L a, L b) {return !eq(cross(vec(a), vec(b)), 0);}
bool eqL(L a, L b) {return !iLL(a, b) && eq(cross(vec(a), b.first - a.first), 0);}
bool iLS(L a, L b) {return sig(cross(vec(a), b.first)) * sig(cross(vec(a), b.second)) <= 0;}
bool iSS(L a, L b) {
  int cwaf = ccw(a, b.first);
  int cwbf = ccw(b, a.first);
  int cwas = ccw(a, b.second);
  int cwbs = ccw(b, a.second);
  if ((cwaf | cwas | cwbf | cwbs) & ON) return true;
  return ((cwaf | cwas) & (cwbf | cwbs)) == (LEFT | RIGHT);
}

// ツ古ーツ点
P pLL(L a, L b) {return a.first + vec(a) * (cross(vec(b), b.first - a.first) / cross(vec(b), vec(a)));}

// ツ仰猟猟」
double dLP(L l, P x) {return abs(cross(vec(l), x - l.first)) / abs(vec(l));}
double dSP(L s, P x) {
  if (dot(vec(s), x - s.first) <= 0) return abs(x - s.first);
  if (dot(-vec(s), x - s.second) <= 0) return abs(x - s.second);
  return dLP(s, x);
}
double dLL(L a, L b) {return iLL(a, b) ? 0 : dLP(a, b.first);}
double dLS(L a, L b) {return iLS(a, b) ? 0 : min(dLP(a, b.first), dLP(a, b.second));}
double dSS(L a, L b) {return iSS(a, b) ? 0 : min(min(dSP(a, b.first), dSP(a, b.second)), min(dSP(b, a.first), dSP(b, a.second)));}

// ツ板シツ陳シツ静シツ猟債づ敖づ個古ーツ債キツ板サツ津ィ
bool iLH(L a, L b) {return iLL(a, b) && ccw(b, pLL(a, b)) & (ON | FRONT);}
bool iHH(L a, L b) {return iLH(a, b) && iLH(b, a);}
bool iHS(L a, L b) {return iLS(a, b) && iLH(b, a);}

// ツ陳シツ行
bool orth(P a, P b) {return eq(dot(a, b), 0);}
// ツ閉スツ行
bool prll(P a, P b) {return eq(cross(a, b), 0);}

// ツ円
struct C{
  P c;
  double r;
  C() {}
  C(P c, double r) : c(c), r(r) {}
};

// 2ツ円ツづ個暗環置ツ甘鳴係
enum RELATION{SAME = 1, CONTAIN = 2, OVER = 4, NO_CROSS = 8, ONE_CROSS = 16, ONE_INSIDE_CROSS = 32, TWO_CROSS = 64};
int cRel(C c1, C c2) {
  double d = abs(c1.c - c2.c);
  if (near(c1.c, c2.c) && eq(d, 0)) return SAME;
  if (sig(d - (c1.r - c2.r)) < 0) return OVER;
  if (sig(d - (c2.r - c1.r)) < 0) return CONTAIN;
  if (eq(d, c1.r - c2.r)) return ONE_INSIDE_CROSS;
  if (eq(d, c1.r + c2.r)) return ONE_CROSS;
  if (sig(d - (c1.r + c2.r)) > 0) return NO_CROSS;
  return TWO_CROSS;
}

bool iCC(C a, C b) {return cRel(a, b) & (ONE_INSIDE_CROSS | ONE_CROSS | TWO_CROSS);}
// ツ点ツつェツ円ツづ可甘慊づ慊づェツづゥツつゥ
bool iCP(C c, P p) {return sig(abs(p - c.c) - c.r) <= 0;}
// ツ古ーツ債キツ板サツ津ィ
bool iCL(C c, L l) {return sig(c.r - dLP(l, c.c)) >= 0;}
// ツ円ツづ?古ーツ債キツつケツつクツ環ョツ全ツづ可甘慊づ慊づェツづ?づ?療?つ「ツ湘ェツ債?づ?&ツ暗按降ツづーツ催ュツ渉?
bool iCS(C c, L s) {return sig(c.r - dSP(s, c.c)) >= 0 && sig(c.r - max(abs(s.first - c.c), abs(s.second - c.c))) <= 0;}

// ツ古ーツ点
pair<P, P> pCC(C a, C b) {
  double d = abs(b.c - a.c);
  double x = (d * d + a.r * a.r - b.r * b.r) / (2 * d);
  P e = (b.c - a.c) / abs(b.c - a.c), w = e * P(0, 1) * sqrt(max(a.r * a.r - x * x, 0.));
  return make_pair(a.c + e * x - w, a.c + e * x + w);
}
pair<P, P> pCL(C c, L l) {
  P h = perp(l, c.c);
  P e = vec(l) / abs(vec(l)) * sqrt(max(c.r * c.r - norm(h - c.c), 0.0));
  return make_pair(h - e, h + e);
}

// ツ角ツづ個禿?外ツ板サツ津ィ ツ角abツづ個禿?閉板づ可つ?づェツづ篠青ウツ、ツ陛督湘」ツづ?ツ、ツ外ツ閉板づ債閉?
int sAP(P a, P b, P c) {
  return sig(cross(a, c)) - sig(cross(b, c)) - sig(cross(a, b));
}

P p1, p2;
double len;
vector<pair<C, pair<double, double> > > ld, rd;
Pol pol;

int main() {
  for (;;) {
    cin >> len >> p1.X >> p1.Y >> p2.X >> p2.Y;
    if (eq(len, 0) && near(p1, 0) && near(p2, 0)) break;
    ld.clear();
    rd.clear();
    if (sig(p1.X) > 0 && sig(p2.X) > 0) {
      swap(p1.X, p1.Y);
      swap(p2.X, p2.Y);
    } else if (sig(p1.X) < 0 && sig(p2.X) < 0) {
      p1.X *= -1;
      p2.X *= -1;
      swap(p1.X, p1.Y);
      swap(p2.X, p2.Y);
    } else if (sig(p1.Y) > 0 && sig(p2.Y) > 0) {
    } else if (sig(p1.Y) < 0 && sig(p2.Y) < 0) {
      p1.Y *= -1;
      p2.Y *= -1;
    } else {
      assert(0);
    }
    //cout << p1 << p2 << endl;
    pol.clear();
    pol.push_back(p1);
    pol.push_back(P(p1.X, p2.Y));
    pol.push_back(P(p2));
    pol.push_back(P(p2.X, p1.Y));
    C c = C(0, len);
    double th = 0;
    rep (i, 6) {
      vector<P> v;
      rep (j, 4) {
	if (iCS(c, L(pol[j], pol[(j + 1) % 4]))) {
	  pair<P, P> pp = pCL(c, L(pol[j], pol[(j + 1) % 4]));
	  if (sig(abs(pp.first - c.c) - c.r) <= 0 && ccw(L(pol[j], pol[(j + 1) % 4]), pp.first) == ON) v.push_back(pp.first);
	  if (sig(abs(pp.second - c.c) - c.r) <= 0 && ccw(L(pol[j], pol[(j + 1) % 4]), pp.second) == ON) v.push_back(pp.second);
	}
      }
      rep (j, 4) {
	if (sig(abs(pol[j] - c.c) - c.r) <= 0) v.push_back(pol[j]);
      }
      if (v.size() == 0u) {
	ld.push_back(make_pair(c, make_pair(PI / 2, PI)));
	break;
      }
      P p = 0;
      double theta = 3 * PI;
      rep (j, v.size()) {
	//cout << v[j] << endl;
	if (near(c.c, v[j])) continue;
	P t  = conj((v[j] - c.c) * plr(th));
 	double at = ang(t);
	//cout << p << theta << t << at << endl;
	if (sig(at - theta) < 0) {
	  p = t;
	  theta = at;
	} else if (eq(at, theta) && abs(t) > abs(p)) {
	  p = t;
	  theta = at;
	}
      }
      //cout << p << endl;
      p = conj(p) * plr(-th) + c.c;
      ld.push_back(make_pair(c, make_pair(PI - (PI + theta + th), PI - th)));
      th += PI + theta;
      //cout << c.r << " " << abs(p - c.c) << endl;
      if (eq(c.r, abs(p - c.c))) break;
      c = C(p, c.r - abs(p - c.c));
      //cout << c.c << c.r << endl;
    }
    c = C(0, len);
    th = 0;
    rep (i, 6) {
      vector<P> v;
      rep (j, 4) {
	if (iCS(c, L(pol[j], pol[(j + 1) % 4]))) {
	  pair<P, P> pp = pCL(c, L(pol[j], pol[(j + 1) % 4]));
	  if (sig(abs(pp.first - c.c) - c.r) <= 0 && ccw(L(pol[j], pol[(j + 1) % 4]), pp.first) == ON) v.push_back(pp.first);
	  if (sig(abs(pp.second - c.c) - c.r) <= 0 && ccw(L(pol[j], pol[(j + 1) % 4]), pp.second) == ON) v.push_back(pp.second);
	}
      }
      rep (j, 4) {
	if (sig(abs(pol[j] - c.c) - c.r) <= 0) v.push_back(pol[j]);
      }
      if (v.size() == 0u) {
	rd.push_back(make_pair(c, make_pair(0, PI / 2)));
	break;
      }
      P p = 0;
      double theta = 3 * PI;
      rep (j, v.size()) {
	if (near(c.c, v[j])) continue;
	P t  = (v[j] - c.c) * plr(-PI - th);
	double at = ang(t);
	if (sig(at - theta) < 0) {
	  p = t;
	  theta = at;
	} else if (eq(at, theta) && abs(t) > abs(p)) {
	  p = t;
	  theta = at;
	}
      }
      p = p * plr(PI + th) + c.c;
      rd.push_back(make_pair(c, make_pair(th, PI + theta + th)));
      th += PI + theta;
      if (eq(c.r, abs(p - c.c))) break;
      c = C(p, c.r - abs(p - c.c));
    }
    /*
    cout << "left" << endl;
    rep (i, ld.size()) cout << ld[i].first.c << ld[i].first.r << " " << ld[i].second.first << " " << ld[i].second.second << endl;
    cout << "right" << endl;
    rep (i, rd.size()) cout << rd[i].first.c << rd[i].first.r << " " << rd[i].second.first << " " << rd[i].second.second << endl;
    //*/
    double res;
    rep (i, ld.size()) rep (j, rd.size()) {
      P p = 0;
      if (iCC(ld[i].first, rd[j].first)) {
	pair<P, P> pp = pCC(ld[i].first, rd[j].first);
	if (sAP(plr(ld[i].second.first), plr(ld[i].second.second), pp.first - ld[i].first.c) >= 0 && sAP(plr(rd[j].second.first), plr(rd[j].second.second), pp.first - rd[j].first.c) >= 0) {
	  p = pp.first;
	}
	if (sAP(plr(ld[i].second.first), plr(ld[i].second.second), pp.second - ld[i].first.c) >= 0 && sAP(plr(rd[j].second.first), plr(rd[j].second.second), pp.second - rd[j].first.c) >= 0) {
	  if (p == 0. || ang((p - ld[i].first.c) * plr(ld[i].second.first)) >= ang((pp.second - ld[i].first.c) * plr(ld[i].second.first))) {
	    p = pp.second;
	  }
	}
      }
      if (p != 0.) {
	//cout << i << " " << j << endl;
	res = len * PI;
	rep (ii, i) res += ld[ii].first.r * (ang(plr(ld[ii].second.first), plr(ld[ii].second.second)));
	rep (jj, j) res += rd[jj].first.r * (ang(plr(rd[jj].second.first), plr(rd[jj].second.second)));
	res += ld[i].first.r * ang(plr(ld[i].second.second), p - ld[i].first.c);
	res += rd[j].first.r * ang(plr(rd[j].second.first), p - rd[j].first.c);
	printf("%.12lf\n", res);
	goto aaa;
      }
    }
    //cout << "hoge" << endl;
    res = len * PI;
    rep (i, ld.size()) res += ld[i].first.r * ang(plr(ld[i].second.first), plr(ld[i].second.second));
    rep (j, rd.size()) res += rd[j].first.r * ang(plr(rd[j].second.first), plr(rd[j].second.second));
    printf("%.12lf\n", res);
  aaa:;
  }
  return 0;
}

Measured memory_bytes: 0