#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
vector<pair<int, int>> v[N], g[N];
priority_queue<pair<long long, int>> pq;
long long e[N] = {}, dist[N] = {}, cost[N] = {};
int n, m, in, out;
inline void dijkstra(int node, bool vv) {
  for (int i = 1; i <= n; ++i) e[i] = (long long)1e15;
  pq.push({0, node});
  e[node] = 0;
  while (!pq.empty()) {
    int a = pq.top().second;
    pq.pop();
    for (auto u : (vv) ? v[a] : g[a]) {
      if (e[u.first] > (e[a] + u.second)) {
        e[u.first] = e[a] + u.second;
        pq.push({-e[u.first], u.first});
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (e[i] <= dist[node]) g[node].push_back({i, cost[node]});
  }
}
int main() {
  cin >> n >> m >> in >> out;
  for (int i = 1; i <= m; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    v[x].push_back({y, c});
    v[y].push_back({x, c});
  }
  for (int i = 1; i <= n; ++i) cin >> dist[i] >> cost[i];
  for (int i = 1; i <= n; ++i) dijkstra(i, true);
  dijkstra(in, false);
  if (e[out] < (long long)1e15)
    cout << e[out] << "\n";
  else
    cout << -1 << "\n";
  return 0;
}
