#include <bits/stdc++.h>
using namespace std;
const long long N = 1111, INF = 0x3f3f3f3f3f3f3f3f;
long long d[N][N], t[N], c[N], n;
vector<pair<long long, long long> > adj[N], r_adj[N];
void dijkstra(long long s, long long dist[N]) {
  priority_queue<pair<long long, long long> > pq;
  for (long long i = 1; i <= n; i++) dist[i] = INF;
  pq.push(make_pair(0, s));
  dist[s] = 0;
  while (!pq.empty()) {
    long long u, x;
    tie(x, u) = pq.top();
    pq.pop();
    if (-x > dist[u]) continue;
    for (auto v : adj[u]) {
      if (dist[v.first] > dist[u] + v.second) {
        dist[v.first] = dist[u] + v.second;
        pq.push(make_pair(-dist[v.first], v.first));
      }
    }
  }
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  long long m, x, y;
  cin >> n >> m >> x >> y;
  for (long long i = 1; i <= m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  for (long long i = 1; i <= n; i++) {
    cin >> t[i] >> c[i];
    dijkstra(i, d[i]);
  }
  for (long long i = 1; i <= n; i++) {
    adj[i].clear();
    for (long long j = 1; j <= n; j++) {
      if ((i ^ j) && d[i][j] <= t[i]) {
        adj[i].push_back(make_pair(j, c[i]));
      }
    }
  }
  dijkstra(x, d[x]);
  d[x][y] = (d[x][y] < INF) ? d[x][y] : -1;
  cout << d[x][y] << endl;
}
