#include <bits/stdc++.h>
using namespace std;
int n, m;
long long total[1010], price[1010];
vector<int> adj[1010], G[1010];
vector<long long> cost[1010];
void dijkstra(int s) {
  priority_queue<pair<int, long long> > q;
  long long dist[1010];
  bool vis[1010];
  for (int i = 0; i < n; i++) {
    dist[i] = 10000000000000000LL;
    vis[i] = false;
  }
  dist[s] = 0LL;
  q.push(pair<int, long long>(0LL, s));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      if (dist[v] > dist[u] + cost[u][i]) {
        dist[v] = dist[u] + cost[u][i];
        q.push(pair<int, long long>(-dist[v], v));
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (i != s && dist[i] <= total[s]) G[s].push_back(i);
  return;
}
long long dijkstra(int s, int t) {
  priority_queue<pair<int, long long> > q;
  long long dist[1010];
  bool vis[1010];
  for (int i = 0; i < n; i++) {
    dist[i] = 10000000000000000LL;
    vis[i] = false;
  }
  dist[s] = 0LL;
  q.push(pair<int, long long>(0LL, s));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (u == t) break;
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (dist[v] > dist[u] + price[u]) {
        dist[v] = dist[u] + price[u];
        q.push(pair<int, long long>(-dist[v], v));
      }
    }
  }
  return dist[t];
}
int main() {
  int s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  while (m--) {
    int u, v;
    long long w;
    cin >> u >> v >> w;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    cost[u].push_back(w);
    cost[v].push_back(w);
  }
  for (int i = 0; i < n; i++) cin >> total[i] >> price[i];
  for (int i = 0; i < n; i++) dijkstra(i);
  long long ans = dijkstra(s, t);
  if (ans == 10000000000000000LL)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
