#include <bits/stdc++.h>
using namespace std;
int n, m;
int start, ending;
vector<pair<long long int, int>> grafo[100100];
vector<pair<long long int, int>> grafo2[100100];
long long int preco[100100];
long long int limite[100100];
long long int dist[100100];
void Dijkstra(int s) {
  for (int i = 1; i <= n; i++) {
    dist[i] = 999999999999999LL;
  }
  dist[s] = 0;
  priority_queue<pair<long long int, int>, vector<pair<long long int, int>>,
                 greater<pair<long long int, int>>>
      fila;
  fila.push(pair<long long int, int>(dist[s], s));
  while (!fila.empty()) {
    int v = fila.top().second;
    long long int dv = fila.top().first;
    fila.pop();
    if (dv > dist[v]) continue;
    for (pair<long long int, int> p : grafo[v]) {
      int u = p.second;
      long long int le = p.first;
      if (dv + le < dist[u]) {
        dist[u] = dv + le;
        fila.push(pair<long long int, int>(dist[u], u));
      }
    }
  }
}
void Dijkstra2(int s) {
  for (int i = 1; i <= n; i++) {
    dist[i] = 999999999999999LL;
  }
  dist[s] = 0;
  priority_queue<pair<long long int, int>, vector<pair<long long int, int>>,
                 greater<pair<long long int, int>>>
      fila;
  fila.push(pair<long long int, int>(dist[s], s));
  while (!fila.empty()) {
    int v = fila.top().second;
    long long int dv = fila.top().first;
    fila.pop();
    if (dv > dist[v]) continue;
    for (pair<long long int, int> p : grafo2[v]) {
      int u = p.second;
      long long int le = p.first;
      if (dv + le < dist[u]) {
        dist[u] = dv + le;
        fila.push(pair<long long int, int>(dist[u], u));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  cin >> start >> ending;
  for (int i = 1; i <= m; i++) {
    int u, v;
    long long int w;
    cin >> u >> v >> w;
    grafo[u].push_back(pair<long long int, int>(w, v));
    grafo[v].push_back(pair<long long int, int>(w, u));
  }
  for (int i = 1; i <= n; i++) {
    cin >> limite[i] >> preco[i];
  }
  for (int i = 1; i <= n; i++) {
    Dijkstra(i);
    for (int j = 1; j <= n; j++) {
      if (i != j and dist[j] <= limite[i]) {
        grafo2[i].push_back(pair<long long int, int>(preco[i], j));
      }
    }
  }
  Dijkstra2(start);
  if (dist[ending] >= 999999999999999LL)
    cout << -1 << endl;
  else
    cout << dist[ending] << endl;
}
