#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const long long int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
void dijkstra(int src, vector<long long int> &dist,
              vector<vector<pair<int, int>>> &adj) {
  fill(dist.begin(), dist.end(), LLONG_MAX);
  dist[src] = 0;
  queue<pair<long long int, int>> pq;
  pq.push({0, src});
  while (!pq.empty()) {
    pair<long long int, int> node = pq.front();
    int u = node.second;
    long long int d = node.first;
    pq.pop();
    if (dist[u] < d) continue;
    for (auto &e : adj[u]) {
      int v = e.first;
      long long int w = e.second;
      if (dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        pq.push({dist[v], v});
      }
    }
  }
}
void cp() {
  int n, m, src, dest;
  cin >> n >> m >> src >> dest;
  src--, dest--;
  vector<vector<pair<int, int>>> adj(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  vector<long long int> dist(n), cost(n, LLONG_MAX);
  cost[src] = 0;
  queue<pair<long long int, int>> pq;
  pq.push({0, src});
  while (!pq.empty()) {
    pair<long long int, int> node = pq.front();
    int u = node.second;
    long long int c = node.first;
    pq.pop();
    dijkstra(u, dist, adj);
    for (int i = 0; i < n; i++) {
      if (dist[i] <= a[u] && i != u) {
        if (cost[i] > cost[u] + b[u]) {
          cost[i] = cost[u] + b[u];
          pq.push({cost[i], i});
        }
      }
    }
  }
  if (cost[dest] == LLONG_MAX)
    cout << -1 << '\n';
  else
    cout << cost[dest] << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    cp();
  }
  return 0;
}
