#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll unimodalFunc(ll t,ll a,ll b){
    return - (t + (b+t+a-1)/(t+a) );
}

double f(double t,double a,double b){
    return  -(t + (b/(t+a)) );
}

static const double RATIO = (1 + sqrt(5.0)) * 0.5;
double search(double left, double right, double a, double b){
	double leftValue = f((left * RATIO + right) / (1 + RATIO),a,b);
	double rightValue = f((left + right * RATIO) / (1 + RATIO),a,b);
	int maxLoop = 72;
    for (int loop = 0; loop < maxLoop; ++loop){
		if (leftValue > rightValue){
			right = (left + right * RATIO) / (1 + RATIO);
			rightValue = leftValue;
			leftValue = f((left * RATIO + right) / (1 + RATIO),a,b);
		} else {
			left = (left * RATIO + right) / (1 + RATIO);
			leftValue = rightValue;
			rightValue = f((left + right * RATIO) / (1 + RATIO),a,b);
		}
	}
	if (leftValue > rightValue){
		right = (left + right * RATIO) / (1 + RATIO);
	} else {
		left = (left * RATIO + right) / (1 + RATIO);
	}
	return (right + left) * 0.5;
}
ll findMaximal(ll from, ll to,ll a,ll b) {
	// d[i] = a[i] - a[i-1]とする。
	// このとき、d[i] > 0 <=> a[i] > a[i-1]なので、
	// d[i] > 0なる最大のi in (from, to)を見つけると、a[i]が最大値
	for (;to - from > 1;) {
		ll mid = (from + to) / 2;
		(unimodalFunc(mid,a,b) - unimodalFunc(mid - 1,a,b) > 0 ? from : to) = mid;
	}

	return from;
}

int main(){
    ll n,m,s,g;
    cin >> n >> m >> s >>g;
    vector<vector<pair<pair<ll,ll>,pair<ll,ll>  > > >p(n);
    s--;g--;
    rep(ss,m){
        ll u,v;
        ll a,b;
        cin >> u >> v >> a >> b;
        u--;v--;
        double sss = search(0.0,100000000.0,(double)a,(double)b);
        ll k = (ll)floor(sss);
        if(unimodalFunc(k,a,b)<unimodalFunc(k+1,a,b)) k = k+1;
        p[u].PB(MP(MP(k,v),MP(a,b)));
        p[v].PB(MP(MP(k,u),MP(a,b)));
    }
    priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll>  >  >pq;
    pq.push(MP(0LL,s));
    vector<ll>dst(n,__LONG_LONG_MAX__);
    dst[s] = 0;
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        ll now = x.first;
        if(dst[x.second]<x.first)continue;
        for(auto v:p[x.second]){
            ll tim = v.first.first;
            ll tar = v.first.second;
            ll a = v.second.first;
            ll b = v.second.second;
            ll tartim;
            if(now >= tim){
                tartim = -unimodalFunc(now,a,b);
            }else{
                tartim = -unimodalFunc(tim,a,b);
            }
            // cout << tim << " " << tar << " " << a << " " << b << endl;
            // cout << tar << " " << tartim << endl;
            if(dst[tar]>tartim){
                dst[tar] = tartim;
                pq.push(MP(tartim,tar));
            }
        }
    }
    // for(int i=0;i<n;i++){
    //     cout << i << " " << dst[i] << endl;
    // }
    if(dst[g]!=__LONG_LONG_MAX__)cout << dst[g] << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 31888