#include <bits/stdc++.h>
using namespace std;
const long long oo = (long long)1e18;
const int N = 1001;
vector<pair<int, int> > adjd[N], adjc[N];
bool vis[N];
long long dist[N];
pair<int, int> cst[N];
int n, m, x, y;
void init() {
  for (int i = 1; i <= n; i++) {
    vis[i] = false;
    dist[i] = oo;
  }
}
void dijkstra1(int u) {
  init();
  dist[u] = 0;
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, u));
  while (!pq.empty()) {
    int node = pq.top().second;
    pq.pop();
    if (vis[node]) continue;
    vis[node] = true;
    for (const auto& edge : adjd[node]) {
      if (dist[node] + edge.second < dist[edge.first]) {
        dist[edge.first] = dist[node] + edge.second;
        pq.push(make_pair(-dist[edge.first], edge.first));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i != u && dist[i] <= cst[u].first) {
      adjc[u].push_back(make_pair(i, cst[u].second));
    }
  }
}
void dijkstra2(int u) {
  init();
  dist[u] = 0;
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, u));
  while (!pq.empty()) {
    int node = pq.top().second;
    pq.pop();
    if (vis[node]) continue;
    vis[node] = true;
    for (const auto& edge : adjc[node]) {
      if (dist[node] + edge.second < dist[edge.first]) {
        dist[edge.first] = dist[node] + edge.second;
        pq.push(make_pair(-dist[edge.first], edge.first));
      }
    }
  }
}
int main() {
  scanf("%d %d %d %d", &n, &m, &x, &y);
  while (m--) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    adjd[u].push_back(make_pair(v, w));
    adjd[v].push_back(make_pair(u, w));
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &cst[i].first, &cst[i].second);
  }
  for (int i = 1; i <= n; i++) {
    dijkstra1(i);
  }
  dijkstra2(x);
  if (dist[y] >= oo) {
    printf("-1\n");
  } else {
    printf("%lld\n", dist[y]);
  }
}
