#include <bits/stdc++.h>
using namespace std;
int N, M;
int x, y;
long long w[1001][1001];
long long t[1001];
long long c[1001];
const long long INFI = 1000000000LL * 1000000000LL;
vector<vector<int> > graph;
vector<vector<long long> > graphw;
long long mindis[1001][1001];
bool visit[1001];
void dijkstra(int start) {
  for (int i = 1; i <= N; ++i) mindis[start][i] = INFI;
  mindis[start][start] = 0;
  memset(visit, false, sizeof(visit));
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  q.push(make_pair(0, start));
  while (q.size() > 0) {
    pair<long long, int> now = q.top();
    q.pop();
    int id = now.second;
    long long nowd = now.first;
    if (visit[id]) continue;
    visit[id] = true;
    for (int i = 0; i < graph[id].size(); ++i) {
      int nextid = graph[id][i];
      long long tw = graphw[id][i];
      if (nowd + tw < mindis[start][nextid]) {
        mindis[start][nextid] = nowd + tw;
        q.push(make_pair(mindis[start][nextid], nextid));
      }
    }
  }
}
vector<vector<int> > costgraph;
vector<vector<long long> > costw;
void york() {
  for (int i = 1; i <= N; ++i) dijkstra(i);
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      if (mindis[i][j] <= t[i]) {
        costgraph[i].push_back(j);
        costw[i].push_back(c[i]);
      }
  graph = costgraph;
  graphw = costw;
  dijkstra(x);
  if (mindis[x][y] != INFI)
    cout << mindis[x][y] << endl;
  else
    cout << -1 << endl;
}
void init() {
  scanf("%d%d", &N, &M);
  graph.resize(N + 1);
  graphw.resize(N + 1);
  costgraph.resize(N + 1);
  costw.resize(N + 1);
  scanf("%d%d", &x, &y);
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j) w[i][j] = INFI;
  for (int i = 0; i < M; ++i) {
    int u, v, ww;
    scanf("%d%d%d", &u, &v, &ww);
    w[u][v] = min(w[u][v], (long long)ww);
    w[v][u] = min(w[v][u], (long long)ww);
  }
  for (int i = 1; i <= N; ++i) {
    int tt, cc;
    scanf("%d%d", &tt, &cc);
    t[i] = tt;
    c[i] = cc;
  }
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      if (w[i][j] != INFI) {
        graph[i].push_back(j);
        graphw[i].push_back(w[i][j]);
      }
}
int main() {
  init();
  york();
  return 0;
}
