#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const long long inf = 1ll << 50;
int v[N], to[N * 2], nxt[N * 2], l[N * 2];
long long t[N], c[N];
bool in[N], use[N];
int que[N * 100];
long long cost[N], spd[N];
inline void make(int fr, int end, long long x, int &p) {
  p++;
  to[p] = end;
  nxt[p] = v[fr];
  l[p] = x;
  v[fr] = p;
}
void init(int n, int m) {
  int a, b, i, j, k, p = 0;
  long long x;
  memset(v, -1, sizeof(v));
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &a, &b);
    cin >> x;
    make(a, b, x, p);
    make(b, a, x, p);
  }
  for (i = 1; i <= n; i++) cin >> t[i] >> c[i];
}
void spfa(int s, int n) {
  int i, j, tail = -1, head = 0, cur;
  memset(in, 0, sizeof(in));
  for (i = 1; i <= n; i++) spd[i] = inf;
  spd[s] = 0;
  in[s] = 1;
  que[++tail] = s;
  while (head <= tail) {
    cur = que[head++];
    in[cur] = 0;
    for (i = v[cur]; i != -1; i = nxt[i]) {
      if (spd[cur] + l[i] < spd[to[i]] && spd[cur] + l[i] <= t[s]) {
        spd[to[i]] = spd[cur] + l[i];
        if (in[to[i]] == 0) {
          in[to[i]] = 1;
          que[++tail] = to[i];
        }
      }
    }
  }
}
long long dij(int s, int end, int n) {
  int i, j, k, mm;
  long long ans = 0;
  memset(use, 0, sizeof(use));
  memset(cost, -1, sizeof(cost));
  cost[s] = 0;
  while (cost[end] == -1) {
    for (i = 1, mm = -1; i <= n; i++) {
      if (cost[i] != -1 && use[i] == 0 &&
          (mm == -1 || cost[i] + c[i] < cost[mm] + c[mm]))
        mm = i;
    }
    if (mm == -1) return -1;
    use[mm] = 1;
    spfa(mm, n);
    for (i = 1; i <= n; i++) {
      if (cost[i] == -1 && spd[i] <= t[mm]) cost[i] = cost[mm] + c[mm];
    }
  }
  return cost[end];
}
int main() {
  int n, m, sta, end;
  cin >> n >> m >> sta >> end;
  init(n, m);
  cout << dij(sta, end, n) << endl;
  return 0;
}
