#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long> > > graph;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
long long dist[1001];
pair<long long, long long> taxi[1001];
long long reach[1001][1001];
int main() {
  int n, m, s, t;
  scanf("%d %d", &n, &m);
  scanf("%d %d", &s, &t);
  graph.resize(n);
  s -= 1;
  t -= 1;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    graph[a - 1].push_back(pair<long long, long long>(b - 1, c));
    graph[b - 1].push_back(pair<long long, long long>(a - 1, c));
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    taxi[i].first = a;
    taxi[i].second = b;
  }
  for (int x = 0; x < n; x++) {
    for (int i = 0; i < n; i++) dist[i] = 1LL << 62;
    dist[x] = 0;
    q.push(pair<long long, long long>(x, 0));
    while (!q.empty()) {
      pair<long long, long long> top = q.top();
      q.pop();
      int x1 = top.first;
      long long cost1 = top.second;
      if (cost1 <= dist[x1]) {
        for (int i = 0; i < graph[x1].size(); i++) {
          int x2 = graph[x1][i].first;
          long long cost2 = graph[x1][i].second;
          if (dist[x2] > dist[x1] + cost2) {
            dist[x2] = dist[x1] + cost2;
            q.push(pair<long long, long long>(x2, dist[x2]));
          }
        }
      }
    }
    for (int i = 0; i < n; i++)
      if (x != i) {
        if (dist[i] <= taxi[x].first) {
          reach[x][i] = dist[i];
        }
      }
  }
  graph.clear();
  graph.resize(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (i != j && reach[i][j] > 0) {
        graph[i].push_back(pair<long long, long long>(j, taxi[i].second));
      }
  }
  for (int i = 0; i < n; i++) dist[i] = 1LL << 62;
  dist[s] = 0;
  q.push(pair<long long, long long>(s, 0));
  while (!q.empty()) {
    pair<long long, long long> top = q.top();
    q.pop();
    int x1 = top.first;
    long long cost1 = top.second;
    if (cost1 <= dist[x1]) {
      for (int i = 0; i < graph[x1].size(); i++) {
        int x2 = graph[x1][i].first;
        long long cost2 = graph[x1][i].second;
        if (dist[x2] > dist[x1] + cost2) {
          dist[x2] = dist[x1] + cost2;
          q.push(pair<long long, long long>(x2, dist[x2]));
        }
      }
    }
  }
  if (dist[t] == (1LL << 62)) {
    printf("-1\n");
  } else {
    cout << dist[t];
  }
  return 0;
}
