#include <cstddef>
#include <tuple>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
namespace loquat {
using vertex_t = size_t;
}
namespace loquat {
namespace edge_param {
struct to_ {
	vertex_t to;
	explicit to_(vertex_t t = 0)
		: to(t)
	{ }
};
template <typename T>
struct weight_ {
	using weight_type = T;
	weight_type weight;
	explicit weight_(const weight_type& w = weight_type())
		: weight(w)
	{ }
};
template <typename T>
using weight = weight_<T>;
}
namespace detail {
template <typename T, typename... Params>
struct edge_param_wrapper : public T, edge_param_wrapper<Params...> {
	template <typename U, typename... Args>
	explicit edge_param_wrapper(U&& x, Args&&... args)
		: T(std::forward<U>(x))
		, edge_param_wrapper<Params...>(std::forward<Args>(args)...)
	{ }
};
template <typename T>
struct edge_param_wrapper<T> : public T {
	template <typename U>
	explicit edge_param_wrapper(U&& x)
		: T(std::forward<U>(x))
	{ }
};
}
template <typename... Params>
struct edge : public detail::edge_param_wrapper<edge_param::to_, Params...> {
	edge()
		: detail::edge_param_wrapper<edge_param::to_, Params...>()
	{ }
	template <typename... Args>
	explicit edge(Args&&... args)
		: detail::edge_param_wrapper<edge_param::to_, Params...>(
			std::forward<Args>(args)...)
	{ }
};
}
namespace loquat {
template <typename EdgeType>
class adjacency_list {
public:
	using edge_type = EdgeType;
	using edge_list = std::vector<edge_type>;
private:
	std::vector<std::vector<EdgeType>> m_edges;
public:
	adjacency_list()
		: m_edges()
	{ }
	explicit adjacency_list(size_t n)
		: m_edges(n)
	{ }
	size_t size() const {
		return m_edges.size();
	}
	const edge_list& operator[](vertex_t u) const {
		return m_edges[u];
	}
	edge_list& operator[](vertex_t u){
		return m_edges[u];
	}
	template <typename... Args>
	void add_edge(vertex_t from, Args&&... args){
		m_edges[from].emplace_back(std::forward<Args>(args)...);
	}
	void add_edge(vertex_t from, const edge_type& e){
		m_edges[from].emplace_back(e);
	}
};
}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
using edge = loquat::edge<loquat::edge_param::weight<tlll>>;
static const ll INF = 1000000000000000000ll;
int main(){
	ios_base::sync_with_stdio(false);
	int n, m, start, goal;
	cin >> n >> m >> start >> goal;
	--start; --goal;
	loquat::adjacency_list<edge> g(n);
	for(int i = 0; i < m; ++i){
		int u, v;
		ll a, b;
		cin >> u >> v >> a >> b;
		--u; --v;
		ll lo = 0, hi = INF;
		while(lo < hi){
			const ll mid = lo + (hi - lo) / 2;
			const double t0 = static_cast<double>(b) / (mid + a);
			const double t1 = static_cast<double>(b) / (mid + a + 1);
			if(t0 - t1 < 1.0){
				hi = mid;
			}else{
				lo = mid + 1;
			}
		}
		g.add_edge(u, v, tlll(a, b, lo));
		g.add_edge(v, u, tlll(a, b, lo));
	}
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	vector<ll> dist(n, INF);
	pq.emplace(0, start);
	dist[start] = 0;
	while(!pq.empty()){
		const ll  t = pq.top().first;
		const int u = pq.top().second;
		pq.pop();
		if(dist[u] < t){ continue; }
		for(const auto& e : g[u]){
			const int v = e.to;
			const ll a = get<0>(e.weight);
			const ll b = get<1>(e.weight);
			const ll k = max(t, get<2>(e.weight));
			const ll t2 = k + (b + k + a - 1) / (k + a);
			if(t2 < dist[v]){
				dist[v] = t2;
				pq.emplace(t2, v);
			}
		}
	}
	if(dist[goal] >= INF){
		cout << -1 << endl;
	}else{
		cout << dist[goal] << endl;
	}
	return 0;
}



Measured memory_bytes: 31844