#include <bits/stdc++.h>
using namespace std;
int main() {
  long long INF = 1 << 30;
  INF = INF * INF;
  vector<pair<long long, long long> > edge[1005];
  long long res[1005];
  for (long long i = 0; i < ((long long)1005); i++) res[i] = -1;
  long long n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<long long> a(m), b(m), c(m), d(n), cost(n);
  for (long long i = 0; i < ((long long)m); i++) cin >> a[i] >> b[i] >> c[i];
  for (long long i = 0; i < ((long long)m); i++) {
    edge[a[i] - 1].push_back(make_pair(b[i] - 1, c[i]));
    edge[b[i] - 1].push_back(make_pair(a[i] - 1, c[i]));
  }
  for (long long i = 0; i < ((long long)n); i++) cin >> d[i] >> cost[i];
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      q;
  q.push(make_pair(0, x - 1));
  while (((long long)q.size())) {
    pair<long long, long long> p = q.top();
    long long now = p.second;
    long long now_cost = p.first;
    q.pop();
    if (res[now] != -1) continue;
    res[now] = now_cost;
    long long can[1005];
    for (long long i = 0; i < ((long long)1005); i++) can[i] = 0;
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long> >,
                   greater<pair<long long, long long> > >
        qq;
    qq.push(make_pair(0, now));
    while (((long long)qq.size())) {
      pair<long long, long long> pp = qq.top();
      qq.pop();
      long long POS = pp.second;
      long long DIS = pp.first;
      if (can[POS]) continue;
      can[POS] = 1;
      for (long long i = 0; i < ((long long)((long long)edge[POS].size()));
           i++) {
        long long dis = DIS + edge[POS][i].second;
        long long to = edge[POS][i].first;
        if (dis <= d[now] && can[to] == 0) qq.push(make_pair(dis, to));
      }
    }
    for (long long i = 0; i < ((long long)1005); i++)
      if (can[i] && i != now && res[i] == -1) {
        q.push(make_pair(now_cost + cost[now], i));
      }
  }
  cout << res[y - 1] << endl;
}
