#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const long double eps = 1e-7;
const int inf = (int)1e9;
const long long linf = (long long)1e18;
const long double pi = acos(-1.0);
const int prime = 748297;
inline void finclude() { srand(time(NULL)); }
int main() {
  finclude();
  int n, m, first, last, from, to, cost;
  cin >> n >> m >> first >> last;
  --first, --last;
  long long d[1010][1010];
  long long w[1010], c[1010];
  for (int i = 0; i < 1010; ++i)
    for (int j = 0; j < 1010; ++j) d[i][j] = linf;
  vector<vector<pair<int, int> > > g(n);
  for (int i = 0; i < m; ++i) {
    cin >> from >> to >> cost;
    --from, --to;
    g[from].push_back(pair<int, int>(to, cost));
    g[to].push_back(pair<int, int>(from, cost));
  }
  for (int i = 0; i < n; ++i) cin >> w[i] >> c[i];
  for (int i = 0; i < n; ++i) {
    long long p[1010] = {};
    d[i][i] = 0;
    priority_queue<pair<int, int> > q;
    q.push(pair<int, int>(0, i));
    while (!q.empty()) {
      int u = q.top().second, cur = -q.top().first;
      q.pop();
      if (cur > d[i][u]) continue;
      for (int j = 0; j < g[u].size(); ++j) {
        int to = g[u][j].first, len = g[u][j].second;
        if (d[i][u] + len < d[i][to]) {
          d[i][to] = d[i][u] + len;
          p[to] = u;
          q.push(pair<int, int>(-d[i][to], to));
        }
      }
    }
  }
  int cur = first;
  bool p[1010] = {};
  long long co[1010];
  for (int i = 0; i < 1010; ++i) co[i] = linf;
  co[cur] = 0;
  while (true) {
    p[cur] = true;
    for (int i = 0; i < n; ++i)
      if (!p[i]) {
        if (d[cur][i] <= w[cur] && co[i] > co[cur] + c[cur])
          co[i] = co[cur] + c[cur];
      }
    cur = first;
    for (int i = 0; i < n; ++i)
      if (!p[i]) {
        if (cur == first || co[cur] > co[i]) cur = i;
      }
    if (cur == first) break;
  }
  if (co[last] > 1e15) {
    cout << -1 << '\n';
    return 0;
  }
  cout << co[last] << '\n';
}
