#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 3;
const long long INF = 1000ll * 1000 * 1000 * 1000 * 1000;
long long n, m, a, b;
vector<pair<long long, long long> > adj[maxn];
long long qq[3][maxn];
long long fa[maxn][maxn];
set<pair<long long, long long> > s[maxn];
set<pair<long long, long long> > st;
long long pr[maxn];
int main() {
  cin >> n >> m >> a >> b;
  a--;
  b--;
  for (int i = 0; i < m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    adj[x].push_back(make_pair(y, z));
    adj[y].push_back(make_pair(x, z));
  }
  for (int i = 0; i < n; i++) cin >> qq[0][i] >> qq[1][i];
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < maxn; j++) fa[i][j] = INF;
  for (int i = 0; i < n; i++) {
    fa[i][i] = 0;
    s[i].insert(make_pair(0, i));
    while (!s[i].empty()) {
      pair<long long, long long> q = *s[i].begin();
      long long x = q.second, f = q.first;
      s[i].erase(s[i].begin());
      for (int j = 0; j < adj[x].size(); j++) {
        long long next = adj[x][j].first, e = adj[x][j].second;
        if (fa[i][next] > e + f) {
          s[i].erase(make_pair(fa[i][next], next));
          fa[i][next] = e + f;
          s[i].insert(make_pair(e + f, next));
        }
      }
    }
  }
  for (int i = 0; i < maxn; i++) pr[i] = INF;
  st.insert(make_pair(0, a));
  pr[a] = 0;
  while (!st.empty()) {
    pair<long long, long long> q = *st.begin();
    long long x = q.second, f = q.first;
    st.erase(st.begin());
    for (int i = 0; i < n; i++)
      if (fa[x][i] <= qq[0][x] && pr[i] > f + qq[1][x]) {
        st.erase(make_pair(pr[i], i));
        pr[i] = f + qq[1][x];
        st.insert(make_pair(f + qq[1][x], i));
      }
  }
  if (pr[b] == INF)
    cout << -1 << endl;
  else
    cout << pr[b] << endl;
  return 0;
}
