#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long> > > adjList;
vector<bool> proccessed;
int main() {
  long long OO = numeric_limits<long long>::max();
  long long n, m;
  cin >> n >> m;
  long long x, y;
  cin >> x >> y;
  x--;
  y--;
  adjList = vector<vector<pair<long long, long long> > >(n);
  long long arr[n][n];
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    adjList[--a].push_back(make_pair(--b, c));
    adjList[b].push_back(make_pair(a, c));
  }
  long long taki[n][2];
  for (long long i = 0; i < n; i++) {
    cin >> taki[i][0] >> taki[i][1];
  }
  for (long long j = 0; j < n; j++) {
    vector<long long> distance(n, OO);
    proccessed = vector<bool>(n, false);
    distance[j] = 0;
    priority_queue<pair<long long, long long> > q;
    q.push(make_pair(0, j));
    while (!q.empty()) {
      long long top = q.top().second;
      q.pop();
      if (proccessed[top]) continue;
      proccessed[top] = true;
      for (auto child : adjList[top]) {
        long long dist = child.second;
        long long node = child.first;
        if (distance[top] + dist < distance[node]) {
          distance[node] = distance[top] + dist;
          q.push(make_pair(-1 * distance[node], node));
        }
      }
    }
    for (long long i = 0; i < n; i++) {
      arr[j][i] = distance[i];
    }
  }
  long long can[n][n];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (taki[i][0] >= arr[i][j]) {
        can[i][j] = taki[i][1];
      } else {
        can[i][j] = OO;
      }
    }
  }
  vector<long long> dist(n, OO);
  proccessed = vector<bool>(n, false);
  dist[x] = 0;
  while (true) {
    long long val = OO;
    long long idx = -1;
    for (long long i = 0; i < n; i++) {
      if (!proccessed[i] && dist[i] < val) {
        val = dist[i];
        idx = i;
      }
    }
    if (idx == -1 || idx == y) {
      break;
    }
    proccessed[idx] = true;
    for (long long i = 0; i < n; i++) {
      if (can[idx][i] != OO && dist[i] > (val = dist[idx] + can[idx][i])) {
        dist[i] = val;
      }
    }
  }
  cout << (dist[y] == OO ? -1 : dist[y]);
  return 0;
}
