Problem: problem

AOR Ika is at the $ S $ th bus stop at time $ 0 $ and wants to go from there to the $ G $ th bus stop. The number of bus stops $ N $ and $ M $ routes (*) connecting different bus stops are given. The bus stops are numbered $ 1, \ dots, and N $, respectively. Each route consists of $ 4 $ values: origin $ u $, destination $ v $, departure time $ t $, and travel time $ c $. You can catch the bus if you are at the departure $ u $ at the time $ t $ and arrive at the destination $ v $ at the time $ t + c $. While not on the bus, AOR Ika gets wet in the rain. When heading to the $ G $ th bus stop through the route that minimizes the time of getting wet in the rain, output the total time of getting wet in the rain from the time $ 0 $ to the arrival at the $ G $ th bus stop.

(*) In graph theory terms, a path is a sequence of vertices and edges, but please note that it is used here to mean edges.



input

Input is given from standard input in the following format.

$ N \ M \ S \ G $
$ u_1 \ v_1 \ t_1 \ c_1 $
$ \ vdots $
$ u_M \ v_M \ t_M \ c_M $

output

Print the minimum amount of time you get wet in one line. Also, output a line break at the end.

Example

Input

2 2 1 2
1 2 10 100
1 2 5 500


Output

5

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (ll i=(b)-1; i>=a;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector<vector<T> >& vec) {
    REP(i,vec.size()) {
        if(i) os << endl;
        os << vec[i];
    }
    return os;
}
struct Edge {
    int from, to, t, c;
};
bool operator<(const Edge& e1, const Edge& e2) {
    return e1.t < e2.t;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, s, g; cin >> n >> m >> s >> g; --s, --g;
    vector<Edge> edges;
    vector<vector<P>> Q(n);
    vector<int> idx(n, 0);
    REP(i, m) {
        int u, v, t, c; cin >> u >> v >> t >> c; --u, --v;
        edges.pb({u, v, t, c});
        Q[u].pb({t, linf});
    }
    REP(i, n) {
        sort(ALL(Q[i]));
    }
    if (Q[s].size() > 0) {
        Q[s][0].second = Q[s][0].first;
    }
    sort(ALL(edges));
    ll ans = linf;
    EACH(e, edges) {
        P& d00 = Q[e.from][idx[e.from]++];
        // wait
        assert(e.t == d00.first);
        if (idx[e.from] < Q[e.from].size()) {
            P& d01 = Q[e.from][idx[e.from]];
            d01.second = min(d01.second, d00.second+(d01.first - d00.first));
        }
        // ride
        if (e.to == g) {
            ans = min(ans, d00.second);
        }
        auto it = lower_bound(ALL(Q[e.to]), P(d00.first+e.c, -1));
        if (it != Q[e.to].end()) {
            it->second = min(it->second, d00.second + (it->first - (e.t+e.c)));
        }
    }
    cout << ans << endl;
}