#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e3 + 10;
const long long INF = 1e14 + 10;
vector<pair<int, int> > adj[MAX_N], adj2[MAX_N];
long long dist[MAX_N];
int n, m, st, ed;
void solve(int x) {
  for (int i = 0; i < MAX_N; i++) dist[i] = INF;
  priority_queue<pair<long long, int> > pq;
  dist[x] = 0;
  pq.push(make_pair(0, x));
  while (!pq.empty()) {
    int now = pq.top().second;
    long long d = -pq.top().first;
    pq.pop();
    if (d != dist[now]) continue;
    for (int i = 0; i < adj[now].size(); i++) {
      int to = adj[now][i].first;
      int cost = adj[now][i].second;
      if (dist[to] > dist[now] + cost) {
        dist[to] = dist[now] + cost;
        pq.push(make_pair(-dist[to], to));
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &st, &ed);
  st--;
  ed--;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  for (int i = 0; i < n; i++) {
    int d, c;
    scanf("%d%d", &d, &c);
    solve(i);
    for (int j = 0; j < n; j++) {
      if (dist[j] <= d) adj2[i].push_back(make_pair(j, c));
    }
  }
  for (int i = 0; i < n; i++) adj[i] = adj2[i];
  solve(st);
  if (dist[ed] == INF)
    puts("-1");
  else
    printf("%I64d\n", dist[ed]);
  return 0;
}
