#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e3 + 100, INF = 1e18;
long long n, m, x, y, Dis[MAXN][MAXN], t[MAXN], c[MAXN], path[MAXN][MAXN],
    NewDis[MAXN];
set<pair<long long, long long> > s;
vector<pair<long long, long long> > adj[MAXN], NewAdj[MAXN];
pair<long long, long long> pi;
void Dijkstra(long long v) {
  Dis[v][v] = 0;
  for (long long i = 0; i < n; i++) s.insert(make_pair(Dis[v][i], i));
  while (!s.empty()) {
    pi = *s.begin();
    s.erase(pi);
    for (long long i = 0; i < (long long)adj[pi.second].size(); i++) {
      long long A = adj[pi.second][i].first;
      if (Dis[v][A] > Dis[v][pi.second] + adj[pi.second][i].second) {
        s.erase(make_pair(Dis[v][A], A));
        Dis[v][A] = Dis[v][pi.second] + adj[pi.second][i].second;
        s.insert(make_pair(Dis[v][A], A));
      }
    }
  }
}
void DijkstraNew(long long v) {
  NewDis[v] = 0;
  for (long long i = 0; i < n; i++) s.insert(make_pair(NewDis[i], i));
  while (!s.empty()) {
    pi = *s.begin();
    s.erase(pi);
    for (long long i = 0; i < (long long)NewAdj[pi.second].size(); i++) {
      long long A = NewAdj[pi.second][i].first;
      if (NewDis[A] > NewDis[pi.second] + NewAdj[pi.second][i].second) {
        s.erase(make_pair(NewDis[A], A));
        NewDis[A] = NewDis[pi.second] + NewAdj[pi.second][i].second;
        s.insert(make_pair(NewDis[A], A));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> x >> y;
  x--, y--;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++) Dis[i][j] = INF;
  fill(NewDis, NewDis + n, INF);
  for (long long i = 0; i < m; i++) {
    long long u, v, weight;
    cin >> u >> v >> weight;
    u--, v--;
    adj[u].push_back(make_pair(v, weight)),
        adj[v].push_back(make_pair(u, weight));
  }
  for (long long i = 0; i < n; i++) {
    Dijkstra(i);
    s.clear();
  }
  for (long long i = 0; i < n; i++) cin >> t[i] >> c[i];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (Dis[i][j] <= t[i])
        path[i][j] = c[i], NewAdj[i].push_back(make_pair(j, c[i]));
      else
        path[i][j] = INF;
    }
  }
  DijkstraNew(x);
  if (NewDis[y] == INF)
    cout << "-1";
  else
    cout << NewDis[y];
}
