#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e3 + 12;
const long long INF = 1e17 + 12;
long long n, m, xxx, yyy, dis[maxN], dist[maxN][maxN], t[maxN], c[maxN],
    comp[maxN], num = 1;
set<pair<long long, long long> > s;
vector<pair<long long, long long> > g[maxN], g2[maxN];
bool mrk[maxN][maxN], mrk2[maxN];
long long mark[maxN];
void dfs(long long v) {
  mark[v] = num;
  comp[num]++;
  for (long long i = 0; i < g[v].size(); i++) {
    long long u = g[v][i].first;
    if (!mark[u]) dfs(u);
  }
}
void expand(long long x, long long v) {
  for (long long i = 0; i < g[x].size(); i++) {
    long long u = g[x][i].first;
    long long val = g[x][i].second;
    if (mrk[v][u]) continue;
    s.insert({dist[v][x] + val, u});
  }
}
pair<long long, long long> extract(long long x) {
  pair<long long, long long> p = {0, 0};
  while (!s.empty()) {
    p = *(s.begin());
    if (mrk[x][p.second])
      s.erase(p);
    else
      break;
  }
  return p;
}
void dijkstra(long long x) {
  s.clear();
  mrk[x][x] = true;
  dist[x][x] = 0;
  expand(x, x);
  while (!s.empty()) {
    pair<long long, long long> p = extract(x);
    if (s.empty()) break;
    long long v = p.second;
    long long val = p.first;
    mrk[x][v] = true;
    dist[x][v] = min(val, dist[x][v]);
    expand(v, x);
  }
}
void expand2(long long x) {
  for (long long i = 0; i < g2[x].size(); i++) {
    long long u = g2[x][i].first;
    long long val = g2[x][i].second;
    if (mrk2[u]) continue;
    s.insert({dis[x] + val, u});
  }
}
pair<long long, long long> extract2() {
  pair<long long, long long> p = {0, 0};
  while (!s.empty()) {
    p = *(s.begin());
    if (mrk2[p.second])
      s.erase(p);
    else
      break;
  }
  return p;
}
void dijk(long long x) {
  s.clear();
  mrk2[x] = true;
  dis[x] = 0;
  expand2(x);
  while (!s.empty()) {
    pair<long long, long long> p = extract2();
    if (s.empty()) break;
    long long v = p.second;
    long long val = p.first;
    mrk2[v] = true;
    dis[v] = min(val, dis[v]);
    expand2(v);
  }
}
int32_t main() {
  cin >> n >> m >> xxx >> yyy;
  xxx--;
  yyy--;
  for (long long i = 0; i < m; i++) {
    long long x, y, val;
    cin >> x >> y >> val;
    x--;
    y--;
    g[x].push_back({y, val});
    g[y].push_back({x, val});
  }
  for (long long i = 0; i < n; i++) {
    if (!mark[i]) {
      num++;
      dfs(i);
    }
    cin >> t[i] >> c[i];
    dis[i] = INF;
    for (long long j = 0; j < n; j++) dist[i][j] = INF;
  }
  for (long long i = 0; i < n; i++) dijkstra(i);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (dist[i][j] <= t[i]) g2[i].push_back({j, c[i]});
    }
  }
  dijk(xxx);
  if (dis[yyy] - INF)
    cout << dis[yyy] << endl;
  else
    cout << -1 << endl;
}
