#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
struct Edge {
  int to;
  long long w;
  bool operator<(const Edge &b) const { return this->w > b.w; }
};
vector<Edge> E1[1001], E2[1001];
bool V[1001];
long long D[1001];
void dijkstra1(int S, int T, int C) {
  for (int i = 1; i <= n; ++i) V[i] = 0, D[i] = 1e18;
  priority_queue<Edge> PQ;
  PQ.push({S, 0}), D[S] = 0;
  while (!PQ.empty()) {
    auto x = PQ.top();
    PQ.pop();
    if (V[x.to]) continue;
    if (x.w > T) break;
    E2[S].push_back({x.to, C});
    V[x.to] = 1;
    for (auto &&j : E1[x.to])
      if (!V[j.to] and D[x.to] + j.w < D[j.to])
        D[j.to] = D[x.to] + j.w, PQ.push({j.to, D[j.to]});
  }
}
long long dijkstra2(int S, int T) {
  for (int i = 1; i <= n; ++i) V[i] = 0, D[i] = 1e18;
  priority_queue<Edge> PQ;
  PQ.push({S, 0}), D[S] = 0;
  while (!PQ.empty()) {
    auto x = PQ.top();
    PQ.pop();
    if (V[x.to]) continue;
    if (x.to == T) break;
    V[x.to] = 1;
    for (auto &&j : E2[x.to])
      if (!V[j.to] and D[x.to] + j.w < D[j.to])
        D[j.to] = D[x.to] + j.w, PQ.push({j.to, D[j.to]});
  }
  return D[T];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> x >> y;
  for (int i = 1, u, v, w; i <= m; ++i) {
    cin >> u >> v >> w;
    E1[u].push_back({v, w});
    E1[v].push_back({u, w});
  }
  for (int i = 1, t, c; i <= n; ++i) {
    cin >> t >> c;
    dijkstra1(i, t, c);
  }
  auto ans = dijkstra2(x, y);
  cout << (ans == 1e18 ? -1 : ans) << endl;
  return 0;
}
