#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    qu;
const int MAXN = 1005;
long long G[MAXN][MAXN];
long long d[MAXN];
int cost[MAXN];
int maxdis[MAXN];
struct node {
  int ith;
  long long d;
} nod;
vector<node> v[MAXN];
const long long INF = (long long)1 << 60;
void Dijkstra(int n, int th) {
  int i, k, x;
  long long dis;
  bool done[MAXN];
  memset(done, 0, sizeof(done));
  for (i = 1; i <= n; i++) d[i] = (i == th ? 0 : INF);
  qu.push(make_pair(d[th], th));
  while (!qu.empty()) {
    pair<long long, int> u = qu.top();
    qu.pop();
    x = u.second;
    if (done[x]) continue;
    done[x] = 1;
    vector<node>::iterator it;
    for (it = v[x].begin(); it != v[x].end(); it++) {
      k = (*it).ith;
      dis = (*it).d;
      if (d[k] > d[x] + dis) {
        d[k] = d[x] + dis;
        qu.push(make_pair(d[k], k));
      }
    }
  }
  return;
}
void init(int n) {
  int i;
  for (i = 1; i <= n; i++) v[i].clear();
}
int main() {
  int n, m, x, y, i, j, u, vv, w;
  long long ans;
  while (scanf("%d%d", &n, &m) != EOF) {
    init(n);
    scanf("%d%d", &x, &y);
    for (i = 1; i <= m; i++) {
      scanf("%d%d%d", &u, &vv, &w);
      nod.ith = vv;
      nod.d = w;
      v[u].push_back(nod);
      nod.ith = u;
      v[vv].push_back(nod);
    }
    for (i = 1; i <= n; i++) {
      scanf("%d%d", &maxdis[i], &cost[i]);
    }
    if (x == y)
      ans = 0;
    else if (m == 0)
      ans = -1;
    else {
      for (i = 1; i <= n; i++) {
        Dijkstra(n, i);
        for (j = 1; j <= n; j++) G[i][j] = d[j];
      }
      init(n);
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
          if (j != i) {
            if (G[i][j] <= maxdis[i]) {
              nod.ith = j;
              nod.d = cost[i];
              v[i].push_back(nod);
            }
          }
        }
      }
      Dijkstra(n, x);
      ans = d[y];
      if (ans >= INF) ans = -1;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
