#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAX = 1e3 + 5;
const long long MAX2 = 11;
const long long MOD = 1000000007;
const long long MOD2 = 2010405347;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;
int n, m, dis[MAX][MAX], a, b, c, t[MAX], cs[MAX], nw, st, en;
long long vis[MAX], nwc;
vector<pair<int, int>> v[MAX];
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
               greater<pair<long long, int>>>
    pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> st >> en;
  for (int i = 1; i <= m; ++i) {
    cin >> a >> b >> c;
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) dis[i][j] = MOD;
  for (int i = 1; i <= n; ++i) {
    dis[i][i] = 0;
    pq.push({0, i});
    while (!pq.empty()) {
      nw = pq.top().second, nwc = pq.top().first, pq.pop();
      if (dis[i][nw] < nwc) continue;
      for (pair<int, int> j : v[nw])
        if (nwc + j.second < dis[i][j.first]) {
          dis[i][j.first] = nwc + j.second;
          pq.push({nwc + j.second, j.first});
        }
    }
  }
  for (int i = 1; i <= n; ++i) cin >> t[i] >> cs[i], vis[i] = INF;
  vis[st] = 0;
  pq.push({0, st});
  while (!pq.empty()) {
    nw = pq.top().second, nwc = pq.top().first, pq.pop();
    if (vis[nw] < nwc) continue;
    for (int i = 1; i <= n; ++i)
      if (nwc + cs[nw] < vis[i] && dis[nw][i] <= t[nw]) {
        vis[i] = nwc + cs[nw];
        pq.push({vis[i], i});
      }
  }
  if (vis[en] == INF) vis[en] = -1;
  cout << vis[en] << '\n';
  return 0;
}
