#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 5;
const int MAXM = 1000 + 5;
const long long INF = (long long)1e14 + 5;
vector<pair<int, long long> > edge[MAXN], edge2[MAXN];
int n, m;
int x, y;
int t[MAXN], c[MAXN];
long long dis[MAXN];
void predo() {
  for (int i = 0; i < n; i++) {
    fill(dis, dis + n, INF);
    queue<int> q;
    set<pair<int, int> > hash;
    q.push(i);
    dis[i] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (vector<pair<int, long long> >::const_iterator itr = edge[u].begin();
           itr != edge[u].end(); itr++) {
        if (dis[u] + itr->second < dis[itr->first] &&
            dis[u] + itr->second <= t[i]) {
          dis[itr->first] = dis[u] + itr->second;
          if (hash.find(make_pair(i, itr->first)) == hash.end()) {
            edge2[i].push_back(make_pair(itr->first, c[i]));
            hash.insert(make_pair(i, itr->first));
          }
          q.push(itr->first);
        }
      }
    }
  }
}
class Cmp {
 public:
  bool operator()(const pair<int, long long>& lhs,
                  const pair<int, long long>& rhs) {
    if (lhs.second != rhs.second) return lhs.second > rhs.second;
  }
};
void dijkstra() {
  priority_queue<pair<int, long long>, vector<pair<int, long long> >, Cmp> pq;
  fill(dis, dis + n, INF);
  dis[x] = 0;
  pq.push(make_pair(x, 0));
  while (!pq.empty()) {
    int u = pq.top().first;
    pq.pop();
    if (u == y) break;
    for (vector<pair<int, long long> >::const_iterator itr = edge2[u].begin();
         itr != edge2[u].end(); itr++) {
      if (dis[u] + itr->second < dis[itr->first]) {
        dis[itr->first] = dis[u] + itr->second;
        pq.push(make_pair(itr->first, dis[itr->first]));
      }
    }
  }
  printf("%I64d\n", dis[y] == INF ? -1 : dis[y]);
}
int main() {
  while (cin >> n >> m) {
    cin >> x >> y;
    --x, --y;
    for (int i = 0; i < n; i++) {
      edge[i].clear();
      edge2[i].clear();
    }
    for (int i = 0; i < m; i++) {
      int u, v, w;
      cin >> u >> v >> w;
      --u, --v;
      edge[u].push_back(make_pair(v, w));
      edge[v].push_back(make_pair(u, w));
    }
    for (int i = 0; i < n; i++) cin >> t[i] >> c[i];
    predo();
    dijkstra();
  }
}
