#include <bits/stdc++.h>
using namespace std;
int n, m, fir, sec;
vector<pair<long long, long long> > v[1007], a[1007];
long long t[1007], c[1007], dis[1007][1007], val[1007];
void dij(int x, long long *d) {
  set<pair<long long, long long> > s;
  for (int i = 0; i < n; i++) d[i] = ((i == x) ? 0 : 1e18);
  s.insert(make_pair(0, x));
  while (!s.empty()) {
    pair<long long, long long> o = *s.begin();
    s.erase(s.begin());
    for (int i = 0; i < a[o.second].size(); i++) {
      long long vali = a[o.second][i].second;
      long long p = a[o.second][i].first;
      if (d[p] > d[o.second] + vali) {
        if (d[p] != 1e18) s.erase(s.find(make_pair(d[p], p)));
        d[p] = d[o.second] + vali;
        s.insert(make_pair(d[p], p));
      }
    }
  }
}
void SoLvE(long long *d) {
  long long x = fir;
  set<pair<long long, long long> > s;
  for (int i = 0; i < n; i++) d[i] = ((i == x) ? 0 : 1e18);
  s.insert(make_pair(0, x));
  while (!s.empty()) {
    pair<long long, long long> o = *s.begin();
    s.erase(s.begin());
    for (int i = 0; i < v[o.second].size(); i++) {
      long long vali = v[o.second][i].second;
      long long p = v[o.second][i].first;
      if (d[p] > d[o.second] + vali) {
        if (d[p] != 1e18) s.erase(s.find(make_pair(d[p], p)));
        d[p] = d[o.second] + vali;
        s.insert(make_pair(d[p], p));
      }
    }
  }
  if (d[sec] == 1e18)
    cout << -1;
  else
    cout << d[sec];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> fir >> sec;
  fir--, sec--;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    a[x].push_back(make_pair(y, z));
    a[y].push_back(make_pair(x, z));
  }
  for (int i = 0; i < n; i++) cin >> t[i] >> c[i];
  for (int i = 0; i < n; i++) {
    dij(i, dis[i]);
    for (int j = 0; j < n; j++)
      if (dis[i][j] <= t[i]) v[i].push_back(make_pair(j, c[i]));
  }
  SoLvE(val);
}
