#include <bits/stdc++.h>
using namespace std;
struct edge {
  int x, y, next, t;
} a[2000 << 2];
set<pair<int, int> > cost;
long long d[2000], cango[2000][2000];
int n, m, S, head[2000], t[2000], c[2000], T;
void dijkstra_time(int s) {
  for (int i = 1; i <= n; ++i) d[i] = 1000000000000000ll;
  d[s] = 0;
  cost.insert(make_pair(0, s));
  int ind, to;
  while (!cost.empty()) {
    ind = (cost.begin())->second;
    cost.erase(cost.begin());
    for (int i = head[ind]; i != 0; i = a[i].next) {
      to = a[i].y;
      if (d[ind] + a[i].t <= t[s] && d[to] > d[ind] + a[i].t) {
        cost.erase(make_pair(d[to], to));
        d[to] = d[ind] + a[i].t;
        cost.insert(make_pair(d[to], to));
      }
    }
  }
}
int main() {
  scanf("%d%d\n%d%d\n", &n, &m, &S, &T);
  for (int i = 1, x, y, z; i <= m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    a[i].next = head[x];
    a[i].x = x;
    a[i].y = y;
    a[i].t = z;
    head[x] = i;
    a[i + m].next = head[y];
    a[i + m].x = y;
    a[i + m].y = x;
    a[i + m].t = a[i].t;
    head[y] = i + m;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &t[i], &c[i]);
  }
  for (int i = 1; i <= n; ++i) {
    dijkstra_time(i);
    for (int j = 1; j <= n; ++j) {
      if (d[j] < 1000000000000000ll) {
        cango[i][j] = d[j];
      } else
        cango[i][j] = -1;
    }
  }
  for (int i = 1; i <= n; ++i) d[i] = 1000000000000000ll;
  d[S] = 0;
  set<pair<int, int> > q;
  q.insert(make_pair(0, S));
  int ind, to;
  while (!q.empty()) {
    ind = q.begin()->second;
    q.erase(q.begin());
    for (int i = 1; i <= n; i++) {
      if (i == ind || cango[ind][i] == -1) continue;
      to = i;
      if (d[to] > d[ind] + c[ind]) {
        q.erase(make_pair(d[to], to));
        d[to] = d[ind] + c[ind];
        q.insert(make_pair(d[to], to));
      }
    }
  }
  if (d[T] < 1000000000000000ll)
    cout << d[T] << endl;
  else
    cout << -1 << endl;
  return 0;
}
