#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 1;
long long n, m, x, y;
vector<pair<long long, long long>> g[N];
long long arrival[N][N], departure[N][N];
void dijkstra(long long source) {
  for (long long i = 1; i < N; i++) {
    arrival[source][i] = 1e18;
    departure[source][i] = 1e18;
  }
  arrival[source][source] = 0;
  set<pair<long long, long long>> pq;
  pq.insert({0, source});
  while (!pq.empty()) {
    auto x = *(pq.begin());
    pq.erase(x);
    departure[source][x.second] = arrival[source][x.second];
    for (auto it : g[x.second]) {
      if (arrival[source][it.first] > departure[source][x.second] + it.second) {
        pq.erase({arrival[source][it.first], it.first});
        arrival[source][it.first] = departure[source][x.second] + it.second;
        pq.insert({arrival[source][it.first], it.first});
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> x >> y;
  for (long long i = 1; i <= m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  for (long long i = 1; i <= n; i++) dijkstra(i);
  for (long long i = 1; i <= n; i++) g[i].clear();
  for (long long i = 1; i <= n; i++) {
    long long t, c;
    cin >> t >> c;
    for (long long j = 1; j <= n; j++) {
      if (arrival[i][j] <= t) g[i].push_back({j, c});
    }
  }
  dijkstra(x);
  if (arrival[x][y] != 1e18)
    cout << arrival[x][y];
  else
    cout << -1;
  return 0;
}
