#include <bits/stdc++.h>
using namespace std;
const long long INF = 1ll << 62;
int main(int argc, char* argv[]) {
  long long n, m, x, y;
  cin >> n >> m;
  cin >> x >> y;
  x--;
  y--;
  vector<pair<int, int> > t;
  vector<vector<pair<int, int> > > g(n), r(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  for (int i = 0; i < n; i++) {
    int l, c;
    cin >> l >> c;
    t.push_back(make_pair(l, c));
  }
  for (int i = 0; i < n; i++) {
    vector<long long> d(n, INF);
    d[i] = 0;
    set<pair<long long, int> > q;
    q.insert(make_pair(d[i], i));
    while (!q.empty()) {
      int c = q.begin()->second;
      q.erase(q.begin());
      for (int j = 0; j < g[c].size(); j++) {
        int t = g[c][j].first;
        int l = g[c][j].second;
        if (d[c] + l < d[t]) {
          q.erase(make_pair(d[t], t));
          d[t] = d[c] + l;
          q.insert(make_pair(d[t], t));
        }
      }
    }
    for (int j = 0; j < n; j++)
      if (d[j] <= t[i].first) r[i].push_back(make_pair(j, t[i].second));
  }
  vector<long long> d(n, INF);
  d[x] = 0;
  set<pair<long long, int> > q;
  q.insert(make_pair(d[x], x));
  while (!q.empty()) {
    int c = q.begin()->second;
    q.erase(q.begin());
    for (int j = 0; j < r[c].size(); j++) {
      int t = r[c][j].first;
      int l = r[c][j].second;
      if (d[c] + l < d[t]) {
        q.erase(make_pair(d[t], t));
        d[t] = d[c] + l;
        q.insert(make_pair(d[t], t));
      }
    }
  }
  if (d[y] != INF)
    cout << d[y] << endl;
  else
    cout << -1 << endl;
  return 0;
}
