Problem: In a forest, there lived a spider named Tim. Tim was so smart that he created a huge, well-structured web. Surprisingly, his web forms a set of equilateral and concentric N-sided polygons whose edge lengths form an arithmetic sequence.

<image>

Figure 1: An example web of Tim

Corresponding vertices of the N-sided polygons lie on a straight line, each apart from neighboring ver- tices by distance 1. Neighboring vertices are connected by a thread (shown in the figure as solid lines), on which Tim can walk (you may regard Tim as a point). Radial axes are numbered from 1 to N in a rotational order, so you can denote by (r, i) the vertex on axis i and apart from the center of the web by distance r. You may consider the web as infinitely large, i.e. consisting of infinite number of N-sided polygons, since the web is so gigantic.

Tim’s web is thus marvelous, but currently has one problem: due to rainstorms, some of the threads are damaged and Tim can’t walk on those parts.

Now, a bug has been caught on the web. Thanks to the web having so organized a structure, Tim accu- rately figures out where the bug is, and heads out for that position. You, as a biologist, are interested in whether Tim is smart enough to move through the shortest possible route. To judge that, however, you need to know the length of the shortest route yourself, and thereby decided to write a program which calculates that length.



Input

The input consists of multiple test cases. Each test case begins with a line containing two integers N (3 ≤ N ≤ 100) and X (0 ≤ X ≤ 100), where N is as described above and X denotes the number of damaged threads. Next line contains four integers rS, iS, rT, and iT, meaning that Tim is starting at (rS, iS) and the bug is at (rT, iT). This line is followed by X lines, each containing four integers rA, iA, rB, and iB, meaning that a thread connecting (rA, iA) and (rB, iB) is damaged. Here (rA, iA) and (rB, iB) will be always neighboring to each other. Also, for all vertices (r, i) given above, you may assume 1 ≤ r ≤ 107 and 1 ≤ i ≤ N.

There will be at most 200 test cases. You may also assume that Tim is always able to reach where the bug is.

The input is terminated by a line containing two zeros.

Output

For each test case, print the length of the shortest route in a line. You may print any number of digits after the decimal point, but the error must not be greater than 0.01.

Example

Input

5 1
2 1 3 2
2 1 2 2
0 0


Output

4.18

Solution (in CPP):

Solution:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
  
const int MAXH = 400;
const int MAXW = 105;
const int MAXX = 101;
const double inf = 1e100;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
  
int N, X;
int si, sj, ti, tj;
int pi[MAXX], pj[MAXX], qi[MAXX], qj[MAXX];
vector<int> vi;
map<int,int> mi, rmi;
int H;
set<pair<pair<int,int>, pair<int,int> > > wall;
double x;
  
struct State {
  int pi, pj;
  double cost;
  bool operator < (const State &s) const {
    return cost > s.cost;
  }
};
double cost[MAXH][MAXW];
  
double getDist(int si, int sj, int ti, int tj) {
  if(si == ti) {
    return rmi[si] * x;
  } else {
    return abs(rmi[si]-rmi[ti]);
  }
}
  
double dijkstra(int si, int sj, int ti, int tj) {
  priority_queue<State> que;
  fill(cost[0], cost[MAXH], inf);
  que.push((State){si,sj,0.0});
  cost[si][sj] = 0.0;
  while(!que.empty()) {
    const State s = que.top();
    que.pop();
    if(cost[s.pi][s.pj] < s.cost) continue;
    if(s.pi == ti && s.pj == tj) return s.cost;
    for(int k = 0; k < 4; ++k) {
      State t = s;
      t.pi += di[k];
      t.pj = (t.pj + dj[k] + N) % N;
      if(t.pi >= H) continue;
      if(t.pi < 0) continue;
      if(wall.count(make_pair(make_pair(s.pi,s.pj),make_pair(t.pi,t.pj)))) continue;
      t.cost += getDist(s.pi, s.pj, t.pi, t.pj);
      if(cost[t.pi][t.pj] <= t.cost) continue;
      que.push(t);
      cost[t.pi][t.pj] = t.cost;
    }
  }
  return inf;
}
  
int main() {
  while(cin >> N >> X && (N|X)) {
    cin >> si >> sj >> ti >> tj;
    --sj; --tj;
    for(int i = 0; i < X; ++i) {
      cin >> pi[i] >> pj[i] >> qi[i] >> qj[i];
      --pj[i]; --qj[i];
    }

    vi.clear();
    vi.push_back(1);
    vi.push_back(si);
    vi.push_back(ti);
    for(int i = 0; i < X; ++i) {
      if(pi[i]-1 >= 1) vi.push_back(pi[i]-1);
      vi.push_back(pi[i]);
      vi.push_back(pi[i]+1);
      if(qi[i]-1 >= 1) vi.push_back(qi[i]-1);
      vi.push_back(qi[i]);
      vi.push_back(qi[i]+1);
    }
    sort(vi.begin(), vi.end());
    vi.erase(unique(vi.begin(), vi.end()), vi.end());
  
    mi.clear();
    rmi.clear();
    for(int i = 0; i < vi.size(); ++i) {
      mi[vi[i]] = i;
      rmi[i] = vi[i];
    }
  
    H = vi.size();
    si = mi[si];
    ti = mi[ti];
    for(int i = 0; i < X; ++i) {
      pi[i] = mi[pi[i]];
      qi[i] = mi[qi[i]];
    }
  
    wall.clear();
    for(int i = 0; i < X; ++i) {
      pair<pair<int,int>, pair<int,int> > p = make_pair(make_pair(pi[i],pj[i]),make_pair(qi[i],qj[i]));
      wall.insert(p);
      swap(p.first, p.second);
      wall.insert(p);
    }
  
    x = sqrt(2.0 - 2.0*cos(M_PI*2.0/(double)N));
  
    printf("%.2f\n", dijkstra(si, sj, ti, tj));
  }
  return 0;
}