#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }

template<class T> void DBG(T&& x) { cerr << x << " "; }
template<class T, class...Args> void DBG(T&& x, Args&&... args) { DBG(x); DBG(args...); }
#define DBG(...) { cerr << "[" << #__VA_ARGS__ << "]: "; DBG(__VA_ARGS__); cerr << endl; }
template<class num> inline void rd(num& x) { cin >> x; }
template <class Ty, class... Args> inline void rd(Ty& x, Args&... args) { rd(x); rd(args...); }
template<class num> inline void print(num&& x) { cout << x; }
template <class Ty, class... Args> inline void print(Ty&& x, Args&&... args) { print(x); print(' '); print(args...); }
#define print(...) print(__VA_ARGS__), print('\n')

const int MAXN = 1e5 + 5;

struct Edge {
	int v;
	ll t, k;
	Edge(int v, ll t, ll k) : v(v), t(t), k(k) {}
};
vector<Edge> edges[MAXN];

ll dist[MAXN];

ll find_next(ll cur, ll t, ll k) {
	ll next = (cur + k - 1) / k * k;
	return next + t;
}

ll dijkstra(int s, int t) {
	fill(dist, dist+MAXN, LLONG_MAX);
	dist[s] = 0;
	priority_queue<pii> pq;
	pq.emplace(0, s);
	while(pq.size()) {
		auto [d, u] = pq.top();
		pq.pop();
		if (-d > dist[u]) continue;
		for (auto e : edges[u]) if (dist[e.v] > find_next(dist[u], e.t, e.k)) {
			dist[e.v] = find_next(dist[u], e.t, e.k);
			pq.emplace(-dist[e.v], e.v);
		}
	}

	return dist[t] == LLONG_MAX ? -1 : dist[t];
}

inline void run_test(int test_number) {
	int n, m, a, b; rd(n, m, a, b);
	for (int i = 0; i < m; i++) {
		int u, v, t, k; rd(u, v, t, k);
		edges[u].emplace_back(v, t, k);
		edges[v].emplace_back(u, t, k);
	}
	print(dijkstra(a, b));
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n_tests = 1;
	for (int i = 1; i <= n_tests; i++) run_test(i);
}
#include <bits/stdc++.h>
using namespace std;
using  ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

int main(){
  int a,b,c,d;
  std::cin >> a >>b>>c>>d;
  std::cout << a*d-b*c << '\n';

  return 0;
}
