#include <bits/stdc++.h>
using namespace std;
int n, m, s, t, u, v, cost, last;
int h[2000], to[2000], ne[2000], c[2000], maxd[2000], w[2000], was[2000];
int d[2000][2000];
long long ans[2000];
set<pair<int, int> > dist;
pair<int, int> pr;
void newedge(int u, int v, int cost) {
  to[last] = v;
  c[last] = cost;
  ne[last] = h[u];
  h[u] = last++;
}
void dijekstra(int s) {
  for (int i = 1; i <= n; i++) d[s][i] = 1000000001;
  d[s][s] = 0;
  dist.clear();
  for (int i = 1; i <= n; i++)
    pr.first = d[s][i], pr.second = i, dist.insert(make_pair(d[s][i], i));
  for (int u, j; dist.size();) {
    u = dist.begin()->second;
    dist.erase(dist.begin());
    if (d[s][u] > maxd[s]) break;
    for (j = h[u]; j != -1; j = ne[j])
      if (d[s][u] + c[j] < d[s][to[j]]) {
        pr.first = d[s][to[j]];
        pr.second = to[j];
        dist.erase(dist.find(pr));
        d[s][to[j]] = d[s][u] + c[j];
        pr.first = d[s][to[j]];
        dist.insert(pr);
      }
  }
  for (int i = 1; i <= n; i++)
    if (i != s && d[s][i] <= maxd[s])
      d[s][i] = w[s];
    else
      d[s][i] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &s, &t);
  memset(h, -1, sizeof(h));
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &cost);
    newedge(u, v, cost);
    newedge(v, u, cost);
  }
  for (int i = 1; i <= n; i++) scanf("%d%d", &maxd[i], &w[i]);
  for (int i = 1; i <= n; i++) dijekstra(i);
  for (int i = 1; i <= n; i++) ans[i] = (1LL << 58);
  ans[s] = 0;
  for (int p;;) {
    p = -1;
    for (int i = 1; i <= n; i++)
      if (!was[i] && (p == -1 || ans[p] > ans[i])) p = i;
    if (p == -1 || ans[p] == (1LL << 58)) break;
    was[p] = 1;
    for (int i = 1; i <= n; i++)
      if (d[p][i] && ans[p] + d[p][i] < ans[i]) ans[i] = ans[p] + d[p][i];
  }
  if (ans[t] == (1LL << 58))
    puts("-1");
  else
    cout << ans[t] << endl;
  return 0;
}
