#include <bits/stdc++.h>
using namespace std;
const int n_max = 1002;
struct Edge {
  int u;
  long w;
};
int n, m, i, j, x, y, u, v, w;
Edge tmp;
vector<Edge> graph[n_max];
long t[n_max], c[n_max];
long d[n_max][n_max];
long long dist[n_max], distm, dismin, umin;
bool fix[n_max];
struct Way {
  int u;
  long d;
};
queue<Way> q;
void bfs(int k, long t) {
  int i, oldu, newu;
  long oldd, newd;
  Way tmp;
  tmp.u = k;
  tmp.d = 0;
  q.push(tmp);
  while (q.size() > 0) {
    tmp = q.front();
    oldu = tmp.u;
    oldd = tmp.d;
    q.pop();
    for (i = 0; i < graph[oldu].size(); i++) {
      newu = graph[oldu][i].u;
      newd = graph[oldu][i].w + d[k][oldu];
      if (newd <= t)
        if (newu != k && d[k][newu] == 0 || d[k][newu] > newd) {
          tmp.u = newu;
          tmp.d = newd;
          q.push(tmp);
          d[k][newu] = newd;
        }
    }
  }
}
int main() {
  cin >> n >> m;
  cin >> x >> y;
  for (i = 1; i <= m; i++) {
    cin >> u >> v >> w;
    tmp.u = v;
    tmp.w = w;
    graph[u].push_back(tmp);
    tmp.u = u;
    graph[v].push_back(tmp);
  }
  for (i = 1; i <= n; i++) {
    cin >> t[i] >> c[i];
    distm += c[i];
  }
  for (i = 1; i <= n; i++) bfs(i, t[i]);
  for (i = 1; i <= n; i++) dist[i] = distm;
  dist[x] = 0;
  for (i = 1; i <= n; i++) {
    dismin = distm;
    for (j = 1; j <= n; j++)
      if (fix[j] == false && dist[j] < dismin) {
        dismin = dist[j];
        umin = j;
      }
    if (dismin == distm) break;
    fix[umin] = true;
    for (j = 1; j <= n; j++)
      if (d[umin][j] > 0)
        if (dist[j] > dismin + c[umin]) dist[j] = dismin + c[umin];
  }
  if (dist[y] == distm)
    cout << -1 << endl;
  else
    cout << dist[y] << endl;
}
