#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int n, m;
int x, y;
vector<int> adj[1005];
long long wg[1005][1005], t[1005], cost[1005], d[1005][1005], tcost[1005];
void dij(int i) {
  fill(d[i], d[i] + 1005, INF);
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      que;
  d[i][i] = 0;
  que.push(make_pair(d[i][i], i));
  while (!que.empty()) {
    long long dis = que.top().first;
    int pos = que.top().second;
    que.pop();
    for (int j = 0; j < adj[pos].size(); j++) {
      if (d[i][adj[pos][j]] > d[i][pos] + wg[pos][adj[pos][j]]) {
        d[i][adj[pos][j]] = d[i][pos] + wg[pos][adj[pos][j]];
        que.push(make_pair(d[i][adj[pos][j]], adj[pos][j]));
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &x, &y);
  for (int i = 1; i <= m; i++) {
    int u, v;
    long long w;
    scanf("%d%d%I64d", &u, &v, &w);
    adj[u].push_back(v);
    adj[v].push_back(u);
    wg[u][v] = (wg[u][v] == 0 ? w : min(wg[u][v], w));
    wg[v][u] = (wg[v][u] == 0 ? w : min(wg[v][u], w));
  }
  for (int i = 1; i <= n; i++) dij(i);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d%I64d", &t[i], &cost[i]);
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      fee;
  fill(tcost, tcost + 1005, INF);
  tcost[x] = 0;
  fee.push(make_pair(tcost[x], x));
  while (!fee.empty()) {
    long long cf = fee.top().first;
    int pos = fee.top().second;
    fee.pop();
    for (int i = 1; i <= n; i++) {
      if (d[pos][i] <= t[pos]) {
        if (tcost[i] > cf + cost[pos]) {
          tcost[i] = cf + cost[pos];
          fee.push(make_pair(tcost[i], i));
        }
      }
    }
  }
  if (tcost[y] == INF)
    printf("-1\n");
  else
    printf("%I64d\n", tcost[y]);
  return 0;
}
