#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline string get() {
  char ch[1000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 21;
const long long maxn = 1e3 + 10;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e18 + 100;
struct state {
  long long v, dis;
  state() {}
  state(long long v, long long dis) : v(v), dis(dis) {}
  inline bool operator<(const state &b) const { return dis > b.dis; }
};
struct connection {
  long long u, c;
  connection() {}
  connection(long long u, long long c) : u(u), c(c) {}
};
vector<connection> g[maxn];
priority_queue<state, vector<state>> pq;
long long maxDis[maxn], price[maxn];
long long di[maxn][maxn];
long long res[maxn];
long long mat[maxn][maxn];
bool mark2[maxn];
bool mark[maxn][maxn];
int32_t main() {
  long long n = in(), m = in();
  long long source = in(), sink = in();
  for (long long i = 0; i < m; i++) {
    long long v = in(), u = in(), c = in();
    g[v].push_back({u, c});
    g[u].push_back({v, c});
  }
  for (long long i = 1; i <= n; i++) maxDis[i] = in(), price[i] = in();
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= n; j++) di[i][j] = INF;
  for (long long i = 1; i <= n; i++) {
    pq.push({i, 0});
    di[i][i] = 0;
    while (pq.empty() == false) {
      long long v = pq.top().v, d = pq.top().dis;
      pq.pop();
      if (mark[i][v]) continue;
      mark[i][v] = true;
      for (auto u : g[v]) {
        if (di[i][u.u] > d + u.c) {
          di[i][u.u] = d + u.c;
          pq.push({u.u, di[i][u.u]});
        }
      }
    }
    for (long long j = 1; j <= n; j++) {
      if (j == i) continue;
      mat[i][j] = (di[i][j] <= maxDis[i] ? price[i] : INF);
    }
  }
  pq.push({source, 0});
  for (long long i = 1; i <= n; i++) res[i] = INF;
  res[source] = 0;
  while (pq.empty() == false) {
    long long v = pq.top().v, d = pq.top().dis;
    pq.pop();
    if (mark2[v]) continue;
    mark2[v] = true;
    for (long long i = 1; i <= n; i++) {
      if (res[i] > d + mat[v][i]) {
        res[i] = d + mat[v][i];
        pq.push({i, res[i]});
      }
    }
  }
  if (res[sink] == INF)
    cout << -1 << "\n";
  else
    cout << res[sink] << "\n";
}
