#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, t[1005], c[1005], d[1005], dis[1005][1005];
vector<pair<long long, long long>> e[1005];
vector<long long> g[1005];
void dijk(long long st) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  pq.push({0, st});
  dis[st][st] = 0;
  while (!pq.empty()) {
    long long u = pq.top().second;
    pq.pop();
    for (auto i : e[u]) {
      long long v = i.first, w = i.second;
      if (dis[st][u] + w < dis[st][v]) {
        dis[st][v] = dis[st][u] + w;
        pq.push({dis[st][v], v});
      }
    }
  }
}
void dijkstra() {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  pq.push({0, x});
  d[x] = 0;
  while (!pq.empty()) {
    long long u = pq.top().second;
    pq.pop();
    for (auto i : g[u]) {
      if (d[i] > d[u] + c[u]) {
        d[i] = d[u] + c[u];
        pq.push({d[i], i});
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> x >> y;
  for (long long i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    e[u].push_back({v, w});
    e[v].push_back({u, w});
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) dis[i][j] = 1e15;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> t[i] >> c[i];
    d[i] = 1e15;
  }
  for (long long i = 1; i <= n; i++) dijk(i);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      if (i != j && dis[i][j] <= t[i]) g[i].push_back(j);
    }
  }
  dijkstra();
  if (d[y] == 1e15)
    cout << -1 << endl;
  else
    cout << d[y] << endl;
  return 0;
}
