#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (1000 + 100);
const long long inf = 1LL << 60;
int N, M, st, ed, vis[MAX_N][MAX_N];
long long dist[MAX_N][MAX_N], cost[MAX_N];
vector<int> from[MAX_N];
vector<pair<int, int> > g[MAX_N];
void Dijkstra(int s) {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 less<pair<long long, int> > >
      pq;
  pq.push(make_pair(-(dist[s][s] = 0), s));
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    if (vis[s][p.second]) continue;
    vis[s][p.second] = 1;
    for (vector<pair<int, int> >::const_iterator it = g[p.second].begin();
         it != g[p.second].end(); ++it) {
      if (-(p.first) + it->second < dist[s][it->first]) {
        dist[s][it->first] = -(p.first) + it->second;
        if (!vis[s][it->first]) {
          pq.push(make_pair(-(dist[s][it->first]), it->first));
        }
      }
    }
  }
}
long long dp[MAX_N];
int mark[MAX_N];
long long getDp() {
  for (int i = (1); i <= (N); ++i) dp[i] = inf, mark[i] = 0;
  dp[st] = 0;
  queue<int> que;
  que.push(st);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    mark[u] = 0;
    for (int i = (0); i < ((int)from[u].size()); ++i) {
      int v = from[u][i];
      if (dp[u] + cost[u] < dp[v]) {
        dp[v] = dp[u] + cost[u];
        if (!mark[v]) {
          mark[v] = 1;
          que.push(v);
        }
      }
    }
  }
  if (dp[ed] >= inf) return -1;
  return dp[ed];
}
int main() {
  cin >> N >> M >> st >> ed;
  for (int i = (1); i <= (M); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  for (int i = (1); i <= (N); ++i) {
    for (int j = (i); j <= (N); ++j)
      dist[j][i] = dist[i][j] = inf, vis[j][i] = vis[i][j] = 0;
  }
  for (int i = (1); i <= (N); ++i) Dijkstra(i);
  for (int i = (1); i <= (N); ++i) {
    int t, c;
    cin >> t >> cost[i];
    for (int j = (1); j <= (N); ++j)
      if (j != i && dist[i][j] <= t) {
        from[i].push_back(j);
      }
  }
  cout << getDp() << endl;
  return 0;
}
