#include <bits/stdc++.h>
using namespace std;
inline int read()
{
char ch=getchar();
int x=0;
while(!isdigit(ch))
ch=getchar();
while(isdigit(ch))
{
x=x*10+ch-'0';
ch=getchar();
}
return x;
}
struct edge
{
int to,nex,l;
double p;
}e[200010];
int point[1010],cnt=-1;
inline const void add(int x,int y,int l,double p)
{
e[++cnt].to=y;
e[cnt].nex=point[x];
point[x]=cnt;
e[cnt].l=l;
e[cnt].p=p;
}
int n,m;
int imp[1010],on[200010],Lock[200010];
inline int spfa1()
{
int q[10000],head=1,tail=0;
int d[1010],vis[1010],i,u,v;
memset(d,0x3f,sizeof(d));
memset(vis,0,sizeof(vis));
q[++tail]=1,vis[1]=1,d[1]=0;
while(head<=tail)
{
u=q[head++];
vis[u]=0;
for(i=point[u];i!=-1;i=e[i].nex)
{
v=e[i].to;
if(d[v]>d[u]+e[i].l)
{
imp[v]=i;
d[v]=d[u]+e[i].l;
if(!vis[v])
{
vis[v]=1;
q[++tail]=v;
}
}
}
}
if(d[n]==d[0])
return 0;
return d[n];
}
inline int spfa2()
{
int q[10000],head=1,tail=0;
int d[1010],vis[1010],i,u,v;
memset(d,0x3f,sizeof(d));
memset(vis,0,sizeof(vis));
q[++tail]=1,vis[1]=1,d[1]=0;
while(head<=tail)
{
u=q[head++];
vis[u]=0;
for(i=point[u];i!=-1;i=e[i].nex)
{
if(Lock[i]) continue;
v=e[i].to;
if(d[v]>d[u]+e[i].l)
{
d[v]=d[u]+e[i].l;
if(!vis[v])
{
vis[v]=1;
q[++tail]=v;
}
}
}
}
if(d[n]==d[0])
return 0;
return d[n];
}
int main()
{
int i,j,k,l;
double p;
memset(point,-1,sizeof(point));
memset(imp,-1,sizeof(imp));
n=read(),m=read();
for(i=1;i<=m;i++)
{
j=read(),k=read(),l=read(),cin>>p;
add(j,k,l,p);
add(k,j,l,p);
}
int a=spfa1();
if(a==0)
{
cout<<"0.0000000";
exit(0);
}
double tot=0,ans=0;
cnt=0;
for(i=2;i<=n;i++)
if(imp[i]!=-1)
{
tot+=e[imp[i]].p;
on[++cnt]=imp[i];
}
ans+=1.0*a*(1-tot);
for(i=1;i<=cnt;i++)
if(e[on[i]].p>0)
{
Lock[on[i]]=1;Lock[on[i]^1]=1;
ans+=1.0*spfa2()*e[on[i]].p;
Lock[on[i]]=0;Lock[on[i]^1]=0;
}
printf("%.7lf",ans);
}