#include <bits/stdc++.h>
using namespace std;
long long n, m, g, h, d[(1010)], c[(1010)];
vector<pair<long long, long long> > e[(1010)];
vector<long long> e2[(1010)];
int main() {
  cin >> n >> m >> g >> h;
  for (int i = 0; i < m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    e[v].push_back({u, w});
    e[u].push_back({v, w});
  }
  for (int p = 1; p <= n; p++) {
    long long t;
    cin >> t >> c[p];
    for (int i = 0; i < (1010); i++) d[i] = ((long long)1e16);
    d[p] = 0;
    set<pair<long long, long long> > s;
    s.insert({0, p});
    while (s.size()) {
      long long x = s.begin()->second;
      s.erase(s.begin());
      for (int i = 0; i < e[x].size(); i++)
        if (d[e[x][i].first] > d[x] + e[x][i].second)
          s.erase({d[e[x][i].first], e[x][i].first}),
              d[e[x][i].first] = d[x] + e[x][i].second,
              s.insert({d[e[x][i].first], e[x][i].first});
    }
    for (int i = 1; i <= n; i++)
      if (i != p && d[i] <= t) e2[p].push_back(i);
  }
  for (int i = 0; i < (1010); i++) d[i] = ((long long)1e16);
  d[g] = 0;
  set<pair<long long, long long> > s;
  s.insert({0, g});
  while (s.size()) {
    long long x = s.begin()->second;
    s.erase(s.begin());
    for (int i = 0; i < e2[x].size(); i++)
      if (d[e2[x][i]] > d[x] + c[x])
        s.erase({d[e2[x][i]], e2[x][i]}), d[e2[x][i]] = d[x] + c[x],
                                          s.insert({d[e2[x][i]], e2[x][i]});
  }
  cout << ((d[h] >= ((long long)1e16)) ? -1 : d[h]);
  return 0;
}
