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 <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <queue>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;

struct Pos{
    int r,i;
    Pos(int r, int i):r(r),i(i){}
    Pos(){}
    bool operator<(const Pos &a) const{
        return (r!=a.r)? r<a.r: i<a.i;
    }
    bool operator==(const Pos &a) const{
        return r==a.r && i==a.i;
    }
};

P convert(const Pos &pos, int n){
    double angle = 2*PI*pos.i/n;
    return P(pos.r, 0) *P(cos(angle), sin(angle));
}

int main(){
    while(1){
        int n,x;
        cin >> n >> x;
        if(n==0) break;

        Pos s,t;
        cin >> s.r >> s.i >> t.r >> t.i;
        s.i--; t.i--;
        set<pair<Pos, Pos> > ng;
        for(int i=0; i<x; i++){
            int rs,is,rt,it;
            cin >> rs >> is >> rt >> it;
            is--; it--;
            pair<Pos, Pos> edge(Pos(rs, is), Pos(rt, it));
            if(edge.second < edge.first){
                swap(edge.first, edge.second);
            }
            ng.insert(edge);
        }

        vector<int> rlist;
        rlist.push_back(s.r);
        rlist.push_back(t.r);
        rlist.push_back(1);
        for(const pair<Pos, Pos> &e: ng){
            rlist.push_back(e.first.r);
            rlist.push_back(e.second.r);
        }
        for(int i=rlist.size()-1; i>=0; i--){
            rlist.push_back(rlist[i]-1);
            rlist.push_back(rlist[i]+1);
        }
        sort(rlist.begin(), rlist.end());
        rlist.erase(unique(rlist.begin(), rlist.end()), rlist.end());
        rlist.erase(rlist.begin());
        rlist.push_back(1e8);

        map<Pos, vector<pair<Pos, double> > > adj;
        for(int i=0; i<(int)rlist.size()-1; i++){
            for(int j=0; j<n; j++){
                Pos curr(rlist[i], j);
                Pos next[2];
                next[0] = Pos(rlist[i], (j+1)%n);
                next[1] = Pos(rlist[i+1], j);
                for(int d=0; d<2; d++){
                    pair<Pos, Pos> edge(curr, next[d]);
                    if(edge.second < edge.first) swap(edge.first, edge.second);
                    if(ng.find(edge) == ng.end()){
                        double dist = abs(convert(curr, n) -convert(next[d], n));
                        adj[curr].emplace_back(next[d], dist);
                        adj[next[d]].emplace_back(curr, dist);
                    }
                }
            }
        }

        priority_queue<pair<double, Pos> > wait;
        wait.push(make_pair(0, s));
        map<Pos, double> mincost;
        for(const auto &key: adj){
            mincost[key.first] = INF;
        }
        mincost[s] = 0;
        while(!wait.empty()){
            double dist = -wait.top().first;
            Pos pos = wait.top().second;
            wait.pop();
            if(dist > mincost[pos] +EPS) continue;
            if(pos == t) break;
            for(const auto &next: adj[pos]){
                double ndist = dist +next.second;
                Pos npos = next.first;
                if(ndist +EPS < mincost[npos]){
                    mincost[npos] = ndist;
                    wait.push(make_pair(-ndist, npos));
                }
            }
        }
        cout << fixed << setprecision(5);
        cout << mincost[t] << endl;
    }
    return 0;
}