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
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1.0e-10;
const double INF = DBL_MAX / 1000;

int main()
{
    int _tmp = 0;

    for(;;){
        int n, x;
        cin >> n >> x;
        if(n == 0)
            return 0;

        int rStart, iStart, rGoal, iGoal;
        cin >> rStart >> iStart >> rGoal >> iGoal;
        
        vector<int> r1(x), i1(x), r2(x), i2(x);
        for(int j=0; j<x; ++j)
            cin >> r1[j] >> i1[j] >> r2[j] >> i2[j];

        // スタート、ゴール、失われた辺が位置する多角形と、その前後の多角形のみに注目
        // また、一番中央にある多角形にも注目する
        map<int, int> rIndex;
        rIndex[1];
        for(int j=0; j<3; ++j){
            rIndex[rStart - 1 + j];
            rIndex[rGoal - 1 + j];
        }
        for(int j=0; j<x; ++j){
            for(int k=0; k<3; ++k){
                rIndex[r1[j] - 1 + k];
                rIndex[r2[j] - 1 + k];
            }
        }
        if(rIndex.begin()->first == 0)
            rIndex.erase(rIndex.begin());

        int m = 0;        // 注目する多角形の数
        vector<int> rPos; // 注目する多角形の位置
        for(map<int, int>::iterator it=rIndex.begin(); it!=rIndex.end(); ++it){
            it->second = m;
            ++ m;
            rPos.push_back(it->first);
        }

        set<pair<pair<int, int>, pair<int, int> > > damage;
        for(int j=0; j<x; ++j){
            damage.insert(make_pair(make_pair(rIndex[r1[j]], i1[j]), make_pair(rIndex[r2[j]], i2[j])));
            damage.insert(make_pair(make_pair(rIndex[r2[j]], i2[j]), make_pair(rIndex[r1[j]], i1[j])));
        }

        vector<vector<double> > minDist(m, vector<double>(n+1, INF));
        minDist[rIndex[rStart]][iStart] = 0.0;
        multimap<double, pair<int, int> > mm;
        mm.insert(make_pair(0.0, make_pair(rIndex[rStart], iStart)));

        for(;;){
            double dist0 = mm.begin()->first;
            int r0 = mm.begin()->second.first;
            int i0 = mm.begin()->second.second;
            mm.erase(mm.begin());
            if(dist0 > minDist[r0][i0] + EPS)
                continue;

            if(r0 == rIndex[rGoal] && i0 == iGoal){
                printf("%.10f\n", dist0);
                break;
            }

            for(int j=0; j<4; ++j){
                double dist = dist0;
                int r = r0;
                int i = i0;
                if(j % 2 == 0){
                    r = r - 1 + j;
                    if(r == -1 || r == m)
                        continue;
                    dist += abs(rPos[r] - rPos[r0]);
                }else{
                    i = (i - 3 + j + n) % n + 1;
                    dist += rPos[r] * sin(PI / n) * 2.0;
                }

                if(damage.find(make_pair(make_pair(r0, i0), make_pair(r, i))) != damage.end())
                    continue;

                if(dist < minDist[r][i] - EPS){
                    minDist[r][i] = dist;
                    mm.insert(make_pair(dist, make_pair(r, i)));
                }
            }
        }
    }
}