#include <bits/stdc++.h>
using namespace std;
long long int u[1004], v[1004], w[1004], d[1004], c[1004], t[1004];
long long int x[1004][1004];
int p[1004][1004];
long long int inf = 100000000000000000;
vector<pair<long long, long long> > a[1004];
vector<long long> b[1004];
long long n;
void dij(long i) {
  set<pair<long long, long long> > s;
  for (long j = 1; j <= n; j++) {
    d[j] = inf;
  }
  d[i] = 0;
  s.insert(make_pair(d[i], i));
  int e = 0;
  while (!s.empty()) {
    long long h = s.begin()->first;
    long long p = s.begin()->second;
    s.erase(s.begin());
    if (h > t[i]) break;
    if (p != i) {
      b[i].push_back(p);
    }
    for (long j = 0; j < a[p].size(); j++) {
      long k = a[p][j].first;
      long long r = a[p][j].second;
      if (d[k] > d[p] + r) {
        s.erase(make_pair(d[k], k));
        d[k] = d[p] + r;
        s.insert(make_pair(d[k], k));
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long m;
  cin >> n >> m;
  long c1, c2;
  cin >> c1 >> c2;
  for (long i = 1; i <= n; i++) {
    for (long j = i + 1; j <= n; j++) {
      x[i][j] = inf;
      x[j][i] = inf;
    }
  }
  for (long i = 1; i <= m; i++) {
    cin >> u[i] >> v[i] >> w[i];
    if (x[u[i]][v[i]] > w[i]) {
      x[u[i]][v[i]] = w[i];
    }
  }
  for (long i = 1; i <= m; i++) {
    if (x[u[i]][v[i]] == w[i] && p[u[i]][v[i]] == 0) {
      p[u[i]][v[i]] = 1;
      a[u[i]].push_back(make_pair(v[i], w[i]));
      a[v[i]].push_back(make_pair(u[i], w[i]));
    }
  }
  for (long i = 1; i <= n; i++) cin >> t[i] >> c[i];
  for (long i = 1; i <= n; i++) {
    dij(i);
  }
  for (long j = 1; j <= n; j++) d[j] = inf;
  d[c1] = 0;
  set<pair<long long, long long> > s;
  s.insert(make_pair(0, c1));
  while (!s.empty()) {
    long long h = s.begin()->first;
    long long p = s.begin()->second;
    s.erase(s.begin());
    if (p == c2) {
      cout << h << endl;
      return 0;
    }
    for (long j = 0; j < b[p].size(); j++) {
      long k = b[p][j];
      if (d[k] > d[p] + c[p]) {
        s.erase(make_pair(d[k], k));
        d[k] = d[p] + c[p];
        s.insert(make_pair(d[k], k));
      }
    }
  }
  cout << "-1" << endl;
}
