#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmax(T &a, T b) {
  return (a > b) ? a : a = b;
}
int N, M, Source, Sink;
int T[1005], C[1005];
int Dist[1005][1005];
long long Step[1005];
bool Known[1005];
vector<pair<int, int> > Adj[1005];
inline void Dijkstra(int S) {
  Dist[S][S] = 0;
  priority_queue<pair<int, int> > pq;
  while (!pq.empty()) pq.pop();
  pq.push(make_pair(0, S));
  while (!pq.empty()) {
    pair<int, int> Cur = pq.top();
    pq.pop();
    if (-Cur.first != Dist[S][Cur.second]) continue;
    for (typeof(Adj[Cur.second].begin()) it = Adj[Cur.second].begin();
         it != Adj[Cur.second].end(); ++it)
      if (Dist[S][it->first] > Dist[S][Cur.second] + it->second) {
        Dist[S][it->first] = Dist[S][Cur.second] + it->second;
        pq.push(make_pair(-Dist[S][it->first], it->first));
      }
  }
}
int main() {
  scanf("%d%d%d%d", &N, &M, &Source, &Sink);
  memset(Dist, 63, sizeof(Dist));
  for (int i = 0; i < M; ++i) {
    int U, V, W;
    scanf("%d%d%d", &U, &V, &W);
    Adj[U].push_back(make_pair(V, W));
    Adj[V].push_back(make_pair(U, W));
  }
  for (int i = 0; i < N; ++i) Dijkstra(i + 1);
  memset(Step, 63, sizeof(Step));
  memset(Known, 0, sizeof(Known));
  for (int i = 1; i <= N; ++i) scanf("%d%d", T + i, C + i);
  Step[Source] = 0;
  for (;;) {
    int ToExt = -1;
    for (int i = 1; i <= N; ++i)
      if (!Known[i] && (ToExt == -1 || Step[ToExt] > Step[i])) ToExt = i;
    if (ToExt == -1) break;
    Known[ToExt] = 1;
    for (int i = 1; i <= N; ++i)
      if (Dist[ToExt][i] <= T[ToExt] && Step[i] > Step[ToExt] + C[ToExt])
        Step[i] = Step[ToExt] + C[ToExt];
  }
  if (Step[Sink] >= 0x3f3f3f3f3f3f3f3fLL)
    puts("-1");
  else
    cout << Step[Sink] << endl;
  return 0;
}
