#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> adj[1005];
long long arr[1005][1005], dep[1005][1005];
long long w[1005];
long long n, m, x, y;
void djikstras(long long so, long long d, long long arr[], long long dep[]) {
  for (long long i = 1; i <= n; i++) {
    arr[i] = 1e16;
    dep[i] = 1e16;
  }
  arr[so] = 0;
  set<pair<long long, long long>> s;
  s.insert({0, so});
  while (!s.empty()) {
    auto x = *(s.begin());
    s.erase(x);
    dep[x.second] = arr[x.second];
    for (auto it : adj[x.second]) {
      if (arr[it.first] > dep[x.second] + it.second) {
        s.erase({arr[it.first], it.first});
        arr[it.first] = dep[x.second] + it.second;
        s.insert({arr[it.first], it.first});
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long s;
  cin >> n >> m >> x >> y;
  for (long long i = 1; i <= m; i++) {
    long long a, b, c;
    cin >> a >> b >> w[i];
    adj[a].push_back({b, w[i]});
    adj[b].push_back({a, w[i]});
  }
  for (long long i = 1; i <= n; i++) djikstras(i, i, arr[i], dep[i]);
  for (long long i = 1; i <= n; i++) adj[i].clear();
  for (long long i = 1; i <= n; i++) {
    long long p, q;
    cin >> p >> q;
    for (long long j = 1; j <= n; j++) {
      if (dep[i][j] <= p) {
        adj[i].push_back({j, q});
      }
    }
  }
  djikstras(x, x, arr[0], dep[0]);
  if (arr[0][y] >= 1e16)
    cout << "-1";
  else
    cout << arr[0][y] << endl;
}
