#include <bits/stdc++.h>
using namespace std;
const int BIG = 1e5 + 9;
const int INF = 1e9 + 9;
const long long BINF = 1e18 + 9;
const double SML = (1e-7);
long long n, m, i, u, v, w, x, y, t, c;
vector<vector<pair<long long, long long> > > adj(1009), costs(1009);
long long dist[1009][1009], cost[1009];
void Dijkstra_dist(long long source) {
  for (int i = 1; i <= n; i++) {
    dist[source][i] = BINF;
  }
  using pll = pair<long long, long long>;
  priority_queue<pll, vector<pll>, greater<pll> > q;
  dist[source][source] = 0;
  q.push({0, source});
  while (!q.empty()) {
    long long node = q.top().second;
    long long d_node = q.top().first;
    q.pop();
    if (d_node > dist[source][node]) {
      continue;
    }
    for (int i = 0; i < adj[node].size(); i++) {
      long long to = adj[node][i].first;
      long long len = adj[node][i].second;
      if (dist[source][node] + len < dist[source][to]) {
        dist[source][to] = dist[source][node] + len;
        q.push({dist[source][to], to});
      }
    }
  }
}
void Dijkstra_cost(long long source) {
  for (int i = 1; i <= n; i++) {
    cost[i] = BINF;
  }
  using pll = pair<long long, long long>;
  priority_queue<pll, vector<pll>, greater<pll> > q;
  cost[source] = 0;
  q.push({0, source});
  while (!q.empty()) {
    long long node = q.top().second;
    long long c_node = q.top().first;
    q.pop();
    if (c_node > cost[node]) {
      continue;
    }
    for (int i = 0; i < costs[node].size(); i++) {
      long long to = costs[node][i].first;
      long long len = costs[node][i].second;
      if (cost[node] + len < cost[to]) {
        cost[to] = cost[node] + len;
        q.push({cost[to], to});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> x >> y;
  for (i = 0; i < m; i++) {
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  for (i = 1; i <= n; i++) {
    cin >> t >> c;
    Dijkstra_dist(i);
    for (int j = 1; j <= n; j++) {
      if (j != i) {
        if (t >= dist[i][j]) {
          costs[i].push_back({j, c});
        }
      }
    }
  }
  Dijkstra_cost(x);
  if (cost[y] == BINF) {
    cout << -1;
  } else {
    cout << cost[y];
  }
  return 0;
}
