#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define eps 1e-10
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;
const int maxn = 1e5+2;
const int INF = 1<<30;
const int mod = 1e9+7;
struct edge {
int v;
double w;
};
int n,m;
vector<edge> e[maxn];
int cnt[maxn], vis[maxn];
double dis[maxn];
bool spfa(int n,double x) {
queue<int> q;
x=log(x);
for(int i=1;i<=n;i++) dis[i]=-1e9,cnt[i]=0,q.push(i),vis[i]=1;
while (!q.empty()) {
int u = q.front();
q.pop(), vis[u] = 0;
for (auto ed : e[u]) {
int v = ed.v;
double w = ed.w;
if (dis[v] < dis[u] + w + x) {
dis[v] = dis[u] + w + x;
cnt[v] = cnt[u] + 1;
if (cnt[v] >= n) {
return false;
}
if (!vis[v]) q.push(v), vis[v] = 1;
}
}
}
return true;
}
void solve(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) e[0].push_back({i,0});
for(int i=1;i<=m;i++){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
e[b].push_back({d,log(1.0*c/a)});
}
double l=0,r=1;
while(abs(r-l)>=eps){
double mid=(l+r)/2;
if(spfa(n,mid)) l=mid;
else r=mid;
}
printf("%0.6lf\n",l);
return;
}
int main()
{
int t = 1;
while(t--){
solve();
}
return 0;
}