#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <cmath>
using namespace std;
template<class T> T ceil(T a, T b) { return a / b + !!(a % b); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using pll = pair<long long, long long>;
using edge = pair<int, pll>;
using Graph = vector<vector<edge>>;
int main() {
    int n, m; cin >> n >> m;
    int s, t; cin >> s >> t; s--, t--;
    Graph g(n);
    while (m--) {
        int u, v; cin >> u >> v; u--, v--;
        long long a, b; cin >> a >> b;
        g[u].emplace_back(v, pll(a, b));
        g[v].emplace_back(u, pll(a, b));
    }
    using T = long long;
    const T INF = numeric_limits<T>::max();
    vector<T> dp(n, INF);
    using P = pair<T, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(dp[s] = 0, s);
    auto calc = [&](long long cur, pll &p) {
        long long a, b; tie(a, b) = p;
        auto f = [&](long long t) { return t + ceil(b, t + a); };
        long long mi = f(cur), t = sqrt(b) - a;
        for (int d: {-1, 0, 1}) if (cur <= t + d) chmin(mi, f(t + d));
        return mi;
    };
    while (!que.empty()) {
        long long cur; int u; tie(cur, u) = que.top(); que.pop();
        if (dp[u] < cur) continue;
        for (auto &e: g[u]) {
            int v = e.first;
            if (chmin(dp[v], calc(cur, e.second))) que.emplace(dp[v], v);
        }
    }
    cout << (dp[t] == INF ? -1 : dp[t]) << endl;
    return 0;
}

