#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, s, t, d[N];
vector<pair<int, int>> adj[N];
long long ans[N], dis[N][N];
bool vis[N];
void dij(int root, int t, int c) {
  for (int i = 1; i <= n; i++) d[i] = t + 1;
  set<pair<int, int>> q;
  q.insert({0, root}), d[root] = 0;
  while (q.size()) {
    auto it = *q.begin();
    q.erase(q.begin());
    int v = it.second, w = it.first;
    for (auto u : adj[v])
      if (w + u.second <= t && w + u.second <= d[u.first]) {
        q.erase({d[u.first], u.first});
        q.insert({d[u.first] = w + u.second, u.first});
      }
  }
  for (int i = 1; i <= n; i++)
    if (d[i] <= t) dis[root][i] = min(dis[root][i], 1LL * c);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dis[i][j] = (1LL << 55) * (i != j);
  cin >> n >> m >> s >> t;
  for (int i = 1, v, u, w; i <= m; i++) {
    cin >> v >> u >> w;
    adj[v].push_back({u, w});
    adj[u].push_back({v, w});
  }
  for (int i = 1, t, c; i <= n; i++) {
    cin >> t >> c;
    dij(i, t, c);
  }
  for (int i = 0; i < N; i++) ans[i] = 1LL << 55;
  vis[s] = true, ans[s] = 0;
  int v = s;
  while (v) {
    for (int i = 1; i <= n; i++) ans[i] = min(ans[i], ans[v] + dis[v][i]);
    v = 0;
    for (int i = 1; i <= n; i++)
      if (!vis[i] && ans[i] < ans[v]) v = i;
    vis[v] = true;
  }
  cout << (ans[t] < ans[0] ? ans[t] : -1) << '\n';
  return 0;
}
