#include <bits/stdc++.h>
using namespace std;
const int M = 1005;
bool visit[M];
long long int dist[M];
vector<pair<int, int> > g1[M], g2[M];
int n, m, t, quant;
void calc(int second) {
  memset(visit, 0, sizeof visit);
  fill_n(dist, M, 1e15);
  dist[second] = 0;
  priority_queue<pair<long long int, int> > q;
  q.push(make_pair(0, second));
  while (!q.empty()) {
    pair<long long int, int> p = q.top();
    q.pop();
    long long int cost = p.first;
    int u = p.second;
    if (!visit[u]) {
      visit[u] = true;
      for (int i = 0; i < g1[u].size(); i++) {
        int v = g1[u][i].first;
        long long int c = g1[u][i].second;
        if (dist[u] + c < dist[v]) {
          dist[v] = dist[u] + c;
          q.push(make_pair(-dist[v], v));
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i == second) continue;
    if (dist[i] <= t) g2[second].push_back(make_pair(i, quant));
  }
}
long long int dijkstra(int second, int d) {
  memset(visit, 0, sizeof visit);
  fill_n(dist, M, 1e15);
  dist[second] = 0;
  priority_queue<pair<long long int, int> > q;
  q.push(make_pair(0, second));
  while (!q.empty()) {
    pair<long long int, int> p = q.top();
    q.pop();
    long long int cost = p.first;
    int u = p.second;
    if (u == d) return -cost;
    if (!visit[u]) {
      visit[u] = true;
      for (int i = 0; i < g2[u].size(); i++) {
        int v = g2[u][i].first;
        long long int c = g2[u][i].second;
        if (dist[u] + c < dist[v]) {
          dist[v] = dist[u] + c;
          q.push(make_pair(-dist[v], v));
        }
      }
    }
  }
  return -1;
}
int main() {
  int a, b;
  scanf("%d %d", &n, &m);
  scanf("%d %d", &a, &b);
  for (int i = 0; i < m; i++) {
    int x, y, w;
    scanf("%d %d %d", &x, &y, &w);
    g1[x].push_back(make_pair(y, w));
    g1[y].push_back(make_pair(x, w));
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &t, &quant);
    calc(i);
  }
  cout << dijkstra(a, b);
  return 0;
}
