#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, int> > adj[(1000)];
long long dist[(1000)];
void dij(int s) {
  fill(dist, dist + (1000), (1LL << 61));
  priority_queue<pair<long long, int> > pq;
  dist[s] = 0;
  pq.push(pair<long long, int>(0, s));
  while (!pq.empty()) {
    int a = pq.top().second;
    long long d = -pq.top().first;
    pq.pop();
    if (d != dist[a]) {
      continue;
    }
    for (int i = 0; i < adj[a].size(); i++) {
      int b = adj[a][i].first;
      long long t = d + adj[a][i].second;
      if (t < dist[b]) {
        dist[b] = t;
        pq.push(pair<long long, int>(-t, b));
      }
    }
  }
}
vector<pair<long long, int> > adj2[(1000)];
int main() {
  int N, M, S, E;
  cin >> N >> M >> S >> E;
  S--;
  E--;
  for (int i = 0; i < M; i++) {
    int a, b, d;
    cin >> a >> b >> d;
    a--;
    b--;
    adj[a].push_back(pair<long long, int>(b, d));
    adj[b].push_back(pair<long long, int>(a, d));
  }
  for (int i = 0; i < N; i++) {
    int d, c;
    cin >> d >> c;
    dij(i);
    for (int j = 0; j < N; j++) {
      if (dist[j] <= d) {
        adj2[i].push_back(pair<long long, int>(j, c));
      }
    }
  }
  for (int i = 0; i < N; i++) {
    adj[i] = adj2[i];
  }
  dij(S);
  cout << (dist[E] != (1LL << 61) ? dist[E] : -1);
}
