#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long> > > g;
vector<vector<pair<long long, long long> > > G;
long long n;
long long t[1005];
long long c[1005];
void dijkstra1(int u) {
  vector<long long> dist(n, 2000000000000);
  dist[u] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  pq.push(pair<long long, long long>(0, u));
  while (!pq.empty()) {
    pair<long long, long long> front = pq.top();
    pq.pop();
    long long u = front.second;
    long long d = front.first;
    if (d > dist[u]) continue;
    for (int j = 0; j < g[u].size(); j++) {
      pair<long long, long long> v = g[u][j];
      if (dist[u] + v.second < dist[v.first]) {
        dist[v.first] = dist[u] + v.second;
        pq.push(pair<long long, long long>(dist[v.first], v.first));
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (i != u && dist[i] <= t[u])
      G[u].push_back(pair<long long, long long>(i, c[u]));
}
void dijkstra2(int x, int y) {
  if (x == y) {
    cout << "0" << endl;
    return;
  }
  vector<long long> dist(n, 2000000000000);
  dist[x] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  pq.push(pair<long long, long long>(0, x));
  while (!pq.empty()) {
    pair<long long, long long> front = pq.top();
    pq.pop();
    long long u = front.second;
    long long d = front.first;
    if (d > dist[u]) continue;
    for (int j = 0; j < G[u].size(); j++) {
      pair<long long, long long> v = G[u][j];
      if (dist[u] + v.second < dist[v.first]) {
        dist[v.first] = dist[u] + v.second;
        pq.push(pair<long long, long long>(dist[v.first], v.first));
      }
    }
  }
  if (dist[y] == 2000000000000)
    cout << "-1" << endl;
  else
    cout << dist[y] << endl;
}
int main() {
  long long m, x, y;
  cin >> n >> m >> x >> y;
  x--;
  y--;
  g.clear();
  g.resize(n);
  G.clear();
  G.resize(n);
  for (int i = 0; i < m; i++) {
    long long a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    g[a].push_back(pair<long long, long long>(b, w));
    g[b].push_back(pair<long long, long long>(a, w));
  }
  for (int i = 0; i < n; i++) cin >> t[i] >> c[i];
  for (int i = 0; i < n; i++) dijkstra1(i);
  dijkstra2(x, y);
  return 0;
}
