#include <bits/stdc++.h>
using namespace std;
int n, s, t, dist[1010], cost[1010];
long long d[1010], c[1010][1010];
vector<pair<long long, int> > adj[1010];
void dijkstra(int start) {
  for (int i = 1; i <= n; i++) d[i] = 99999999999999LL;
  set<pair<long long, int> > Q;
  Q.insert(pair<long long, int>(0, start));
  d[start] = 0;
  while (!Q.empty()) {
    pair<long long, int> top = *Q.begin();
    Q.erase(Q.begin());
    int u = top.second;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].first;
      long long w = adj[u][i].second;
      if (d[v] > d[u] + w) {
        if (d[v] != 99999999999999LL)
          Q.erase(Q.find(pair<long long, int>(d[v], v)));
        d[v] = d[u] + w;
        Q.insert(pair<long long, int>(d[v], v));
      }
    }
  }
  for (int i = 1; i <= n; i++) c[i][start] = c[start][i] = d[i];
}
long long solve() {
  for (int i = 1; i <= n; i++) dijkstra(i);
  for (int i = 1; i <= n; i++) {
    d[i] = 99999999999999LL;
    adj[i].clear();
    for (int j = 1; j <= n; j++)
      if (c[i][j] <= dist[i])
        adj[i].push_back(pair<long long, int>(j, cost[i]));
  }
  d[s] = 0;
  set<pair<long long, int> > Q;
  Q.insert(pair<long long, int>(0, s));
  while (!Q.empty()) {
    pair<long long, int> top = *Q.begin();
    Q.erase(Q.begin());
    int u = top.second;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].first;
      long long w = adj[u][i].second;
      if (d[v] > d[u] + w) {
        if (d[v] != 99999999999999LL)
          Q.erase(Q.find(pair<long long, int>(d[v], v)));
        d[v] = d[u] + w;
        Q.insert(pair<long long, int>(d[v], v));
      }
    }
  }
  return (d[t] != 99999999999999LL) ? d[t] : -1;
}
int main() {
  int m, u, v, w;
  scanf("%d %d", &n, &m);
  scanf("%d %d", &s, &t);
  while (m--) {
    scanf("%d %d %d", &u, &v, &w);
    adj[u].push_back(pair<long long, int>(v, w));
    adj[v].push_back(pair<long long, int>(u, w));
  }
  for (int i = 1; i <= n; i++) scanf("%d %d", &dist[i], &cost[i]);
  cout << solve() << endl;
}
