#include <stdio.h>
#include <iostream>
#include <cstring>
const int maxn = 100005;
const int maxn2 = 1e3+5;
int n,m;
using namespace std;
int head[maxn2],nex[maxn<<1],dis[maxn<<1],we[maxn<<1],q,tag[maxn<<1],tag2[maxn<<1];
double pe[maxn<<1];
inline void connect(int a,int b,int w,double p) {
nex[++q] = head[a],head[a] =q,dis[q] = b,we[q] = w,pe[q] = p;
nex[++q] = head[b],head[b] = q,dis[q] = a,we[q] = w,pe[q] = p;
}
int que[10000000],hh,rr,dist[maxn2],used[maxn2][maxn2],father[maxn2],visit[maxn2];
double sum2;
int mindist = 1e9;
void spfa() {
mindist = 1e9;
for(int i = 0;i<=n;i++) dist[i] = 1e9;
que[rr++] = 1;
visit[1] = 1;
dist[1] = 0;
while(hh!=rr) {
int a = que[hh++];
for(int i = head[a]; i; i = nex[i]) {
if(tag2[i]) continue;
int to = dis[i];
if(dist[to]>dist[a]+we[i]) {
dist[to] = dist[a] + we[i];
used[a][to] = i,father[to] = a;
if(visit[to]==0) visit[to] = 1,que[rr++] = to;
}
}
visit[a] = 0;
}
mindist = dist[n];
}
void dfs(int a) {
if(father[a]==0) return;
if(a!=1) {
int pre= father[a],line = used[pre][a];
tag[line] = 1,sum2+=pe[line];
dfs(father[a]);
}
}
int main() {
scanf("%d%d",&n,&m);
double ans = 0;
double sum = 0;
for(int i = 1; i<=m; i++) {
int x,y,z;
double p;
cin>>x>>y>>z>>p;
connect(x,y,z,p);
sum+=p;
}
spfa();
dfs(n);
if(mindist==1e9) mindist = 0;
ans+= (sum-sum2)*mindist;
ans+=(1-sum)*mindist;
for(int i = 1;i<=m;i++){
int i1 = i*2-1,i2 = i*2;
if(tag[i1]||tag[i2]){
tag2[i1] = tag2[i2] = 1;
spfa();
if(mindist == 1e9) mindist = 0;
ans+= pe[i1]*mindist;
tag2[i1] = tag2[i2] = 0;
}
}
printf("%.7f",ans);
return 0;
}