#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T, class T2>
void smin(T& a, T2 val) {
  if (a > val) a = val;
}
template <class T, class T2>
void smax(T& a, T2 val) {
  if (a < val) a = val;
}
const long long N = 1e3 + 100;
long long n, x, y;
vector<array<long long, 2>> v[N];
vector<array<long long, 2>> g[N];
vector<long long> dijkstra(long long source, long long type = 0) {
  vector<long long> dis(n, 1e18);
  vector<long long> vis(n, false);
  dis[source] = 0;
  multiset<pair<long long, long long>> s;
  s.insert({0, source});
  while (!s.empty()) {
    pair<long long, long long> p = *(s.begin());
    s.erase(s.begin());
    long long weight = p.first, x = p.second;
    if (vis[x]) continue;
    vis[x] = true;
    vector<array<long long, 2>> X;
    if (!type) {
      X = v[x];
    } else {
      X = g[x];
    }
    for (auto i : X) {
      long long weight1 = i[1], e = i[0];
      if (dis[x] + weight1 < dis[e]) {
        dis[e] = dis[x] + weight1;
        s.insert({dis[e], e});
      }
    }
  }
  return dis;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long m;
  cin >> n >> m;
  cin >> x >> y;
  --x, --y;
  for (long long i = 0; i < m; ++i) {
    long long x, y, c;
    cin >> x >> y >> c;
    --x, --y;
    v[x].push_back({y, c});
    v[y].push_back({x, c});
  }
  vector<long long> t(n), cost(n);
  for (long long i = 0; i < n; ++i) {
    cin >> t[i] >> cost[i];
  }
  for (long long i = 0; i < n; ++i) {
    vector<long long> d = dijkstra(i);
    for (long long j = 0; j < n; ++j) {
      if (i == j) continue;
      if (d[j] <= t[i]) {
        g[i].push_back({j, cost[i]});
      }
    }
  }
  vector<long long> ans = dijkstra(x, 1);
  long long ret = ans[y];
  if (ret >= 1e18) {
    ret = -1;
  }
  cout << ret;
  return 0;
}
