#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
const int INF = 1000000001;
void dijkstra(int s, const vector<vector<pair<int, int> > > &G,
              vector<long long> &D) {
  int n = G.size();
  D.clear();
  D.resize(n, -1);
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      Q;
  Q.push(make_pair(0, s));
  D[s] = 0;
  while (!Q.empty()) {
    long long d = Q.top().first;
    int v = Q.top().second;
    Q.pop();
    if (D[v] != d) continue;
    for (__typeof((G[v]).begin()) u = (G[v]).begin(); u != (G[v]).end(); ++u)
      if (D[u->first] == -1 || d + u->second < D[u->first]) {
        D[u->first] = d + u->second;
        Q.push(make_pair(D[u->first], u->first));
      }
  }
}
int main(int argc, char *argv[]) {
  int n, m;
  int s, t;
  scanf("%d %d", &n, &m);
  scanf("%d %d", &s, &t);
  --s, --t;
  vector<vector<pair<int, int> > > G1(n);
  while (m--) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    --a, --b;
    G1[a].push_back(make_pair(b, c));
    G1[b].push_back(make_pair(a, c));
  }
  vector<vector<long long> > D(n);
  for (int i = 0; i < n; ++i) dijkstra(i, G1, D[i]);
  vector<vector<pair<int, int> > > G2(n);
  for (int i = 0; i < n; ++i) {
    int t, c;
    scanf("%d %d", &t, &c);
    for (int j = 0; j < n; ++j)
      if (D[i][j] != -1 && D[i][j] <= t) G2[i].push_back(make_pair(j, c));
  }
  vector<long long> res;
  dijkstra(s, G2, res);
  printf("%I64d\n", res[t]);
  return 0;
}
