#include <bits/stdc++.h>
using namespace std;
const long long OO = 1e18 + 1e5;
int main() {
  bool vis[1001];
  vector<vector<pair<int, long long> > > adj(1001);
  int taxi[1001][2];
  int n = 0, m = 0, x = 0, y = 0, u = 0, v = 0, w = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  vector<long long> dist(1001, OO);
  queue<pair<int, int> > qu;
  scanf("%d%d%d%d", &n, &m, &x, &y);
  while (m--) {
    scanf("%d%d%d", &u, &v, &w);
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  for (int i = 1; i <= n; i++) scanf("%d%d", &taxi[i][0], &taxi[i][1]);
  dist[x] = 0;
  pq.push(make_pair(0, x));
  while (pq.size()) {
    long long d = pq.top().first, node = pq.top().second;
    long long t = taxi[node][0], c = taxi[node][1];
    ;
    pq.pop();
    if (dist[node] < d) continue;
    qu.push(make_pair(t, node));
    memset(vis, 0, sizeof vis);
    while (qu.size()) {
      long long d2 = qu.front().first, node2 = qu.front().second;
      qu.pop();
      vis[node2] = 1;
      for (auto i : adj[node2]) {
        long long a = i.first, b = i.second;
        if (d2 - b >= 0 && !vis[a]) {
          if (dist[node] + c < dist[a]) {
            long long dd = dist[node] + c;
            dist[a] = dd;
            pq.push(make_pair(dd, a));
          }
          qu.push(make_pair(d2 - b, a));
        }
      }
    }
  }
  printf("%I64d", (dist[y] == OO ? -1ll : dist[y]));
  return 0;
}
