#include <bits/stdc++.h>
using namespace std;
int dist[1005][1005];
long long ans[1005][1005];
int num[1005][2];
bool vist[1005];
int n, m;
int st, ed;
void Floyd() {
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (dist[i][k] + dist[k][j] < dist[i][j])
          dist[i][j] = dist[i][k] + dist[k][j];
}
long long SPFAans(int x) {
  int tmp;
  memset(vist, 0, sizeof(vist));
  long long sans[1005];
  for (int i = 1; i <= n; i++) sans[i] = 10000000000005;
  sans[x] = 0;
  deque<int> q;
  vist[x] = true;
  q.push_back(x);
  while (!q.empty()) {
    tmp = q.front();
    q.pop_front();
    for (int i = 1; i <= n; i++) {
      if (sans[tmp] + ans[tmp][i] < sans[i]) {
        sans[i] = sans[tmp] + ans[tmp][i];
        if (!vist[i]) {
          vist[i] = true;
          if (!q.empty()) {
            if (sans[i] > sans[q.front()])
              q.push_back(i);
            else
              q.push_front(i);
          } else
            q.push_back(i);
        }
      }
    }
    vist[tmp] = false;
  }
  return sans[ed];
}
void solve() {
  long long pans;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dist[i][j] <= num[i][0] && ans[i][j] != 0)
        ans[i][j] = (long long)(num[i][1]);
    }
  }
  pans = SPFAans(st);
  if (pans == 10000000000005)
    printf("-1\n");
  else
    printf("%I64d\n", pans);
}
int main() {
  int a, b, c;
  scanf("%d %d", &n, &m);
  scanf("%d %d", &st, &ed);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      dist[i][j] = 1000000005;
      ans[i][j] = 10000000000005;
    }
    dist[i][i] = 0;
    ans[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a, &b, &c);
    if (dist[a][b] > c) {
      dist[a][b] = c;
      dist[b][a] = c;
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &num[i][0], &num[i][1]);
  }
  Floyd();
  solve();
  return 0;
}
