#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  int n,m,s,g;
  scanf("%d %d %d %d",&n,&m,&s,&g);
  s--;g--;
  struct edge{
    Int to,a,b,s;
    edge(){}
    edge(Int to,Int a,Int b):to(to),a(a),b(b){
      s=sqrt((double)b)-a;
      if(s<0) s=0;
    }    
  };
  vector<vector<edge> > G(n);
  for(Int i=0;i<m;i++){
    Int u,v,a,b;
    scanf("%lld %lld %lld %lld",&u,&v,&a,&b);
    u--;v--;
    G[u].emplace_back(v,a,b);
    G[v].emplace_back(u,a,b);
  }
  const Int INF = 1e17;
  using P = pair<Int, Int>;
  priority_queue<P, vector<P>, greater<P> > pq;
  vector<Int> dp(n,INF);

  dp[s]=0;
  pq.emplace(dp[s],s);

  while(!pq.empty()){
    Int x,v;
    tie(x,v)=pq.top();pq.pop();
    if(dp[v]<x) continue;
    
    for(auto e:G[v]){
      for(Int k=-1;k<=1;k++){
	Int t=max(e.s+k,dp[v]);
	Int c=t+(e.b+t+e.a-1)/(t+e.a);
	if(dp[e.to]>c){
	  dp[e.to]=c;
	  pq.emplace(dp[e.to],e.to);
	}
      }
    }
  }
  
  if(dp[g]>=INF) dp[g]=-1;  
  printf("%lld\n",dp[g]);
  return 0;
}

