#include <bits/stdc++.h>
using namespace std;
long long int pw(long long int a, long long int b, long long int mod) {
  if (!b) return 1;
  if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
  return pw(a * a % mod, b / 2, mod) % mod;
}
const long long int MAXN = 1e3 + 10;
const long long int INF = 1e18;
const long long int MOD = 1e9 + 7;
long long int n, m, x, y, mark[MAXN], t[MAXN], cost[MAXN], dp[MAXN], dist[MAXN];
vector<pair<long long int, long long int>> adj[MAXN], g[MAXN];
priority_queue<pair<long long int, long long int>,
               vector<pair<long long int, long long int>>,
               greater<pair<long long int, long long int>>>
    pq;
void Dijk(int u) {
  fill(mark, mark + MAXN, 0);
  fill(dp, dp + MAXN, INF);
  pq.push({0, u});
  dp[u] = 0;
  while (!pq.empty()) {
    int v = pq.top().second;
    pq.pop();
    if (mark[v]) continue;
    mark[v] = 1;
    for (pair<long long int, long long int>& e : g[v]) {
      if (dp[e.first] <= dp[v] + e.second) continue;
      dp[e.first] = dp[v] + e.second;
      pq.push({dp[e.first], e.first});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> x >> y;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> cost[i];
  }
  for (int i = 1; i <= n; i++) {
    Dijk(i);
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (dp[j] > t[i]) continue;
      adj[i].push_back({j, cost[i]});
    }
  }
  fill(dist, dist + MAXN, INF);
  fill(mark, mark + MAXN, 0);
  dist[x] = 0;
  pq.push({0, x});
  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    if (mark[u]) continue;
    mark[u] = 1;
    for (pair<long long int, long long int>& e : adj[u]) {
      if (dist[e.first] <= dist[u] + e.second) continue;
      dist[e.first] = dist[u] + e.second;
      pq.push({dist[e.first], e.first});
    }
  }
  cout << (dist[y] == INF ? -1 : dist[y]) << '\n';
  return 0;
}
