#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using tiii = tuple<int, int, int>;
using str = string;
using ld = long double;
template <class T>
void maxself(T& x, const T& y) {
  x = (y > x ? y : x);
}
template <class T>
void minself(T& x, const T& y) {
  x = (y < x ? y : x);
}
const ld PI = 3.141592653589793238462643;
const ll mod = 1000000007;
struct mi {
  ll val;
  explicit operator int() const { return val; }
  mi() : val(0) {}
  mi(ll v) : val(v % mod) {}
};
mi operator+(const mi& a, const mi& b) { return (a.val + b.val) % mod; }
mi operator*(const mi& a, const mi& b) { return (a.val * b.val) % mod; }
mi operator-(const mi& a, const mi& b) { return (a.val - b.val + mod) % mod; }
const int N = 1000;
int n, m;
int st, ed;
ll dist[N][N];
vector<pll> adj[N];
ll ans_dist[N];
vector<pll> ans_adj[N];
void solve() {
  cin >> n >> m >> st >> ed;
  st--, ed--;
  for (int i = 0; i < (m); i++) {
    int x, y, w;
    cin >> x >> y >> w;
    x--, y--;
    adj[x].emplace_back(y, w);
    adj[y].emplace_back(x, w);
  }
  for (int i = 0; i < (n); i++) {
    ans_dist[i] = LONG_LONG_MAX;
    for (int j = 0; j < (n); j++) dist[i][j] = LONG_LONG_MAX;
  }
  for (int i = 0; i < (n); i++) {
    dist[i][i] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.push({0, i});
    while (int((pq).size())) {
      auto x = pq.top();
      pq.pop();
      if (dist[i][x.second] != x.first) continue;
      for (auto e : (adj[x.second]))
        if (dist[i][e.first] > x.first + e.second) {
          dist[i][e.first] = x.first + e.second;
          pq.push({dist[i][e.first], e.first});
        }
    }
  }
  vector<pll> taxi(n);
  for (int i = 0; i < (n); i++) {
    cin >> taxi[i].first >> taxi[i].second;
  }
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      if (i == j) continue;
      if (dist[i][j] <= taxi[i].first) {
        ans_adj[i].emplace_back(j, taxi[i].second);
      }
    }
  }
  priority_queue<pll, vector<pll>, greater<pll>> pq;
  ans_dist[st] = 0;
  pq.push({0, st});
  while (int((pq).size())) {
    auto x = pq.top();
    pq.pop();
    if (x.first != ans_dist[x.second]) continue;
    for (auto e : (ans_adj[x.second])) {
      if (ans_dist[e.first] > x.first + e.second) {
        ans_dist[e.first] = x.first + e.second;
        pq.push({ans_dist[e.first], e.first});
      }
    }
  }
  if (ans_dist[ed] == LONG_LONG_MAX)
    cout << -1 << '\n';
  else
    cout << ans_dist[ed] << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) solve();
  return 0;
}
