#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int size = 1000;
int n, m, x, y;
vector<pair<int, long long> > A[size + 1];
vector<int> NG[size + 1];
set<pair<long long, int> > myset;
int T[size + 1], C[size + 1], B[size + 1];
long long D[size + 1];
int main() {
  int v1, v2, w;
  cin >> n >> m >> x >> y;
  for (int i = 1; i <= m; i++) {
    cin >> v1 >> v2 >> w;
    A[v1].push_back(make_pair(v2, w));
    A[v2].push_back(make_pair(v1, w));
  }
  for (int i = 1; i <= n; i++) cin >> T[i] >> C[i];
  long long inf = 1000000000;
  inf *= inf;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) D[j] = inf;
    memset(B, 0, sizeof(B));
    int v = i;
    myset.clear();
    myset.insert(make_pair(0, v));
    D[v] = 0;
    while (!myset.empty()) {
      v = (*myset.begin()).second;
      B[v] = 1;
      if (D[v] <= T[i]) NG[i].push_back(v);
      myset.erase(myset.begin());
      for (int j = 0; j < A[v].size(); j++) {
        v1 = A[v][j].first;
        w = A[v][j].second;
        if (!B[v1] && D[v1] > D[v] + w) {
          myset.erase(make_pair(D[v1], v1));
          myset.insert(make_pair((long long)D[v] + (long long)w, v1));
          D[v1] = D[v] + w;
        }
      }
    }
  }
  int v = x;
  for (int j = 1; j <= n; j++) D[j] = inf;
  memset(B, 0, sizeof(B));
  myset.clear();
  myset.insert(make_pair(0, x));
  D[x] = 0;
  while (!myset.empty()) {
    v = (*myset.begin()).second;
    B[v] = 1;
    if (v == y) {
      cout << D[v] << endl;
      return 0;
    }
    myset.erase(myset.begin());
    for (int j = 0; j < NG[v].size(); j++) {
      v1 = NG[v][j];
      if (!B[v1] && D[v1] > D[v] + C[v]) {
        myset.erase(make_pair(D[v1], v1));
        D[v1] = (long long)D[v] + (long long)C[v];
        myset.insert(make_pair(D[v1], v1));
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
