#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, int> > pq;
vector<int> adj[1003];
vector<long long> cst[1003];
long long dist[1003][1003];
void dijkstra1(int s) {
  dist[s][s] = 0;
  pq.push({0, s});
  while (!pq.empty()) {
    long long y = -pq.top().first;
    int x = pq.top().second;
    pq.pop();
    if (dist[s][x] != y) continue;
    for (int i = 0; i < adj[x].size(); i++) {
      int z = adj[x][i];
      long long c = cst[x][i];
      if (dist[s][z] > dist[s][x] + c)
        dist[s][z] = dist[s][x] + c, pq.push({-dist[s][z], z});
    }
  }
  while (!pq.empty()) pq.pop();
  return;
}
long long dd[1003], cc[1003];
long long val[1003];
void dijkstra2(int s, int n) {
  pq.push({0, s});
  while (!pq.empty()) {
    long long y = -pq.top().first;
    int x = pq.top().second;
    pq.pop();
    if (val[x] != y) continue;
    for (int i = 1; i <= n; i++) {
      if (dist[x][i] <= dd[x]) {
        if (val[i] > cc[x] + val[x])
          val[i] = cc[x] + val[x], pq.push({-val[i], i});
      }
    }
  }
  return;
}
int main() {
  long long z;
  int n, m, s, e, x, y;
  scanf("%d %d %d %d", &n, &m, &s, &e);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %lld", &x, &y, &z);
    adj[x].push_back(y);
    adj[y].push_back(x);
    cst[x].push_back(z);
    cst[y].push_back(z);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) dist[i][j] = 1000000000000000ll;
  for (int i = 1; i <= n; i++) dijkstra1(i);
  for (int i = 1; i <= n; i++) scanf("%lld %lld", &dd[i], &cc[i]);
  for (int i = 1; i <= n; i++) val[i] = 1000000000000000ll;
  val[s] = 0;
  dijkstra2(s, n);
  if (val[e] == 1000000000000000ll) val[e] = -1;
  printf("%lld\n", val[e]);
  return 0;
}
