#include <bits/stdc++.h>
using namespace std;
using plt = pair<long long, int>;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
constexpr int N = 1e3 + 10;
const int MOD = 1e9 + 7;
const long long INF = 8e18;
vector<pair<int, int> > adj[N], g[N], taxi;
priority_queue<plt, vector<plt>, greater<plt> > pq;
int n, m, x, y;
long long d[N];
void dijkstra() {
  while ((int)((pq).size())) {
    int v = pq.top().second;
    long long dv = pq.top().first;
    pq.pop();
    if (dv != d[v]) continue;
    for (auto node : adj[v]) {
      if (node.second + dv < d[node.first]) {
        d[node.first] = node.second + dv;
        pq.push({d[node.first], node.first});
      }
    }
  }
}
void newdij() {
  while ((int)((pq).size())) {
    int v = pq.top().second;
    long long dv = pq.top().first;
    pq.pop();
    if (dv != d[v]) continue;
    for (auto node : g[v]) {
      if (node.second + dv < d[node.first]) {
        d[node.first] = node.second + dv;
        pq.push({d[node.first], node.first});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> x >> y;
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  taxi.push_back({0, 0});
  for (int i = 1; i <= n; ++i) {
    int ti, ci;
    cin >> ti >> ci;
    taxi.push_back({ti, ci});
  }
  for (int i = 1; i <= n; ++i) {
    fill(d, d + N, INF);
    d[i] = 0;
    pq.push({0, i});
    dijkstra();
    auto [ti, ci] = taxi[i];
    for (int j = 1; j <= n; ++j) {
      if (d[j] <= ti && j != i) {
        g[i].push_back({j, ci});
      }
    }
  }
  fill(d, d + N, INF);
  d[x] = 0;
  pq.push({0, x});
  newdij();
  cout << (d[y] == INF ? -1 : d[y]) << endl;
  return 0;
}
