#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
set<pair<long long, int> > q;
vector<pair<int, long long> > g[1001];
int x, y, i, j, n, m, s, t, v;
long long D[1001][1001], uns[1001], U, w, T[1001], C[1001];
int main() {
  U = 1000000000000000LL;
  cin >> n >> m;
  cin >> s >> t;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> w;
    g[x].push_back(make_pair(y, w));
    g[y].push_back(make_pair(x, w));
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (i == j)
        D[i][j] = 0;
      else
        D[i][j] = U;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) uns[j] = U;
    q.clear();
    uns[i] = 0;
    q.insert(make_pair(0, i));
    for (;;) {
      if (q.empty()) break;
      v = q.begin()->second;
      q.erase(q.begin());
      for (j = 0; j <= (int)g[v].size() - 1; j++) {
        int to;
        long long len;
        to = g[v][j].first;
        len = uns[v] + g[v][j].second;
        if (len < uns[to]) {
          q.erase(make_pair(uns[to], to));
          uns[to] = len;
          q.insert(make_pair(uns[to], to));
        }
      }
    }
    for (j = 1; j <= n; j++) {
      D[i][j] = min(D[i][j], uns[j]);
      D[j][i] = min(D[j][i], uns[j]);
    }
  }
  for (i = 1; i <= n; i++) cin >> T[i] >> C[i];
  for (i = 1; i <= n; i++) {
    g[i].clear();
    for (j = 1; j <= n; j++)
      if (i != j && D[i][j] <= T[i]) {
        g[i].push_back(make_pair(j, C[i]));
      }
  }
  for (i = 1; i <= n; i++) uns[i] = U;
  q.clear();
  uns[s] = 0;
  q.insert(make_pair(0, s));
  for (;;) {
    if (q.empty()) break;
    v = q.begin()->second;
    q.erase(q.begin());
    for (j = 0; j <= (int)g[v].size() - 1; j++) {
      int to;
      long long len;
      to = g[v][j].first;
      len = uns[v] + g[v][j].second;
      if (len < uns[to]) {
        q.erase(make_pair(uns[to], to));
        uns[to] = len;
        q.insert(make_pair(uns[to], to));
      }
    }
  }
  if (uns[t] >= 10000000000000LL)
    cout << "-1" << endl;
  else
    cout << uns[t] << endl;
}
