#include <bits/stdc++.h>
using namespace std;
long long mp[1001][1001];
long long mp2[1001][1001];
vector<pair<long long, long long> > edge[1001];
long long n, m, x, y, u, v, w, t, c;
void dijkstra(long long v, long long *d) {
  long long t;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  for (long long i = 1; i <= n; i++) d[i] = 1000000000000000000LL;
  d[v] = 0;
  pq.push(make_pair(0, v));
  while (!pq.empty()) {
    t = pq.top().second;
    pq.pop();
    for (long long i = 0; i < edge[t].size(); i++)
      if (d[edge[t][i].first] > d[t] + edge[t][i].second) {
        d[edge[t][i].first] = d[t] + edge[t][i].second;
        pq.push(make_pair(d[edge[t][i].first], edge[t][i].first));
      }
  }
  return;
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  scanf("%I64d%I64d", &x, &y);
  for (long long i = 0; i < m; i++) {
    scanf("%I64d%I64d%I64d", &u, &v, &w);
    edge[u].push_back(make_pair(v, w));
    edge[v].push_back(make_pair(u, w));
  }
  for (long long i = 1; i <= n; i++) dijkstra(i, mp[i]);
  for (long long i = 1; i <= n; i++) edge[i].clear();
  for (long long i = 1; i <= n; i++) {
    scanf("%I64d%I64d", &t, &c);
    for (long long j = 1; j <= n; j++)
      if (j != i && mp[i][j] <= t) edge[i].push_back(make_pair(j, c));
  }
  dijkstra(x, mp2[x]);
  if (mp2[x][y] != 1000000000000000000LL)
    printf("%I64d\n", mp2[x][y]);
  else
    printf("-1\n");
  return 0;
}
