#include <bits/stdc++.h>
using namespace std;
int n;
void dijkstra(int V, long long *dis, vector<pair<int, int> > v[]) {
  for (int q = 1; q <= n; q++) dis[q] = (long long)(1e15 + 1);
  dis[V] = 0;
  set<pair<int, int> > s;
  s.insert(make_pair(0, V));
  while (!s.empty()) {
    int vertex = (*s.begin()).second;
    s.erase(s.begin());
    for (int i = 0; i < v[vertex].size(); i++) {
      int N = v[vertex][i].first;
      int w = v[vertex][i].second;
      if (dis[vertex] + w < dis[N]) {
        s.erase(make_pair(dis[N], N));
        dis[N] = dis[vertex] + w;
        s.insert(make_pair(dis[N], N));
      }
    }
  }
}
int main() {
  int m, X, Y, x, y, w;
  vector<pair<int, int> > v[1002];
  vector<pair<int, int> > finalV[1002];
  cin >> n >> m;
  cin >> X >> Y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> w;
    v[x].push_back(make_pair(y, w));
    v[y].push_back(make_pair(x, w));
  }
  int t[n + 1], c[n + 1];
  long long dis[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> c[i];
    dijkstra(i, dis, v);
    for (int j = 1; j <= n; j++)
      if (dis[j] <= t[i]) finalV[i].push_back(make_pair(j, c[i]));
  }
  dijkstra(X, dis, finalV);
  if (dis[Y] == 1e15 + 1)
    cout << "-1";
  else
    cout << dis[Y];
}
