#include <bits/stdc++.h>
using namespace std;
vector<pair<int, long long> > G[2000];
int n, m, x, y;
long long best[2000];
long long cost[2000];
long long dist[2000];
long long GW[2000][2000];
long long inf = 1e13;
void bfs(int s) {
  queue<pair<int, long long> > path;
  path.push(make_pair(s, 0));
  pair<int, long long> cur, nex;
  int i;
  for (i = 0; i < n; i++) best[i] = inf;
  best[s] = 0;
  GW[s][s] = 0;
  while (path.size()) {
    cur = path.front();
    path.pop();
    if (cur.second > best[cur.first]) continue;
    for (i = 0; i < G[cur.first].size(); i++) {
      nex = cur;
      nex.first = G[cur.first][i].first;
      nex.second += G[cur.first][i].second;
      if (best[nex.first] > nex.second && nex.second <= dist[s]) {
        path.push(nex);
        GW[s][nex.first] = cost[s];
        best[nex.first] = nex.second;
      }
    }
  }
}
long long bfs(int s, int y) {
  queue<pair<int, long long> > path;
  path.push(make_pair(s, 0));
  pair<int, long long> cur, nex;
  int i;
  for (i = 0; i < n; i++) best[i] = inf;
  best[s] = 0;
  while (path.size()) {
    cur = path.front();
    path.pop();
    if (cur.second > best[cur.first]) continue;
    for (i = 0; i < n; i++) {
      if (GW[cur.first][i] != inf) {
        nex = cur;
        nex.first = i;
        nex.second += GW[cur.first][i];
        if (best[nex.first] > nex.second) {
          path.push(nex);
          best[nex.first] = nex.second;
        }
      }
    }
  }
  return best[y];
}
int main() {
  int i, j, k, s, e;
  long long w, c, d;
  cin >> n >> m >> x >> y;
  x--;
  y--;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) GW[i][j] = inf;
  for (i = 0; i < m; i++) {
    cin >> s >> e >> d;
    s--;
    e--;
    GW[s][e] = min(GW[s][e], d);
    GW[e][s] = min(GW[e][s], d);
  }
  for (i = 0; i < n; i++) cin >> dist[i] >> cost[i];
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      if (GW[i][j] != inf) {
        G[i].push_back(make_pair(j, GW[i][j]));
        GW[i][j] = inf;
      }
  for (i = 0; i < n; i++) {
    bfs(i);
  }
  d = bfs(x, y);
  if (d == inf)
    cout << -1 << endl;
  else
    cout << d << endl;
}
