#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;
}


Measured memory_bytes: 9932