#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const long long INF = 1e18 + 5;
long long N, M, X, Y;
vector<long long> COST, DIST;
vector<vector<pair<long long, long long>>> OG, G;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  cin >> X >> Y;
  X--, Y--;
  OG.resize(N, vector<pair<long long, long long>>());
  G.resize(N, vector<pair<long long, long long>>());
  COST.resize(N);
  DIST.resize(N);
  long long u, v, w;
  for (int i = (0); i < int(M); i++) {
    cin >> u >> v >> w;
    u--, v--;
    OG[u].push_back({w, v});
    OG[v].push_back({w, u});
  }
  for (int i = (0); i < int(N); i++) cin >> DIST[i] >> COST[i];
  for (int i = (0); i < int(N); i++) {
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long>>,
                   greater<pair<long long, long long>>>
        PQ;
    vector<long long> distTo(N, INF);
    PQ.push({0, i});
    distTo[i] = 0;
    while (PQ.size()) {
      auto k = PQ.top();
      PQ.pop();
      for (auto &e : OG[k.second]) {
        long long d = k.first + e.first;
        if (d <= DIST[i] and d < distTo[e.second]) {
          distTo[e.second] = d;
          PQ.push({d, e.second});
          G[i].push_back({COST[i], e.second});
        }
      }
    }
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      PQ;
  vector<long long> costTo(N, INF);
  PQ.push({0, X});
  costTo[X] = 0;
  while (PQ.size()) {
    auto k = PQ.top();
    PQ.pop();
    for (auto &e : G[k.second]) {
      long long c = k.first + e.first;
      if (c < costTo[e.second]) {
        costTo[e.second] = c;
        PQ.push({c, e.second});
      }
    }
  }
  if (costTo[Y] == INF)
    cout << -1;
  else
    cout << costTo[Y];
  cout << '\n';
  return 0;
}
