// USACO 2019 December Contest, Gold
//Problem 1. Milk Pumping
#include<bits/stdc++.h>
#define int long long
using namespace std;
void usaco(){
freopen("pump.in","r",stdin);
freopen("pump.out","w",stdout);
}
const int N=2e5+5;
int n,m,dis[N];
vector<tuple<int,int,int>> a[N];
int dij(){
// d f s x
priority_queue<tuple<int,int,int,int>>q;
q.push({0,0,1e18,1}); dis[1]=0;
while(!q.empty()){
auto [d,f,s,x]=q.top(); q.pop(); d=-d;
if(d>dis[x]) continue;
for(auto [i,ff,ss]:a[x]){
if(dis[i]<(int)(min(s,ss)/(f+ff))){
dis[i]=(int)(min(s,ss)/(f+ff));
q.push({-dis[i],f+ff,min(s,ss),i});
}
}
}
return dis[n];
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
usaco();
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v,f,s; cin>>u>>v>>f>>s; s*=1000000;
a[u].push_back({v,f,s});
a[v].push_back({u,f,s});
}
cout<<dij();
}
Ly8gVVNBQ08gMjAxOSBEZWNlbWJlciBDb250ZXN0LCBHb2xkCi8vUHJvYmxlbSAxLiBNaWxrIFB1bXBpbmcKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnZvaWQgdXNhY28oKXsKCWZyZW9wZW4oInB1bXAuaW4iLCJyIixzdGRpbik7CglmcmVvcGVuKCJwdW1wLm91dCIsInciLHN0ZG91dCk7Cn0KY29uc3QgaW50IE49MmU1KzU7CmludCBuLG0sZGlzW05dOwp2ZWN0b3I8dHVwbGU8aW50LGludCxpbnQ+PiBhW05dOyAKaW50IGRpaigpewoJCQkJICAvLyAgICAgIGQgICBmICAgcyAgIHgKCXByaW9yaXR5X3F1ZXVlPHR1cGxlPGludCxpbnQsaW50LGludD4+cTsKCXEucHVzaCh7MCwwLDFlMTgsMX0pOyBkaXNbMV09MDsKCXdoaWxlKCFxLmVtcHR5KCkpewoJCWF1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