#include <bits/stdc++.h>
using namespace std;
const int C = 1005;
int n, m, x, y;
vector<pair<int, long long>> g[C];
bool visited[C];
long long mdist[C];
long long cost[C];
long long dist[C];
priority_queue<pair<long long, int>> qu;
vector<pair<int, long long>> tab[C];
void dfs(int x, long long left, int start) {
  visited[x] = 1;
  qu.push(make_pair(-left, x));
  while (!qu.empty()) {
    long long d = -qu.top().first;
    int act = qu.top().second;
    qu.pop();
    for (int i = 0; i < g[act].size(); i++) {
      int bct = g[act][i].first;
      long long r = g[act][i].second;
      if (!visited[bct] && r <= d) {
        visited[bct] = 1;
        tab[start].push_back(make_pair(bct, cost[start]));
        qu.push(make_pair(-(d - r), bct));
      }
    }
  }
}
void dijk(int x) {
  qu.push(make_pair(0, x));
  while (!qu.empty()) {
    long long d = qu.top().first;
    int act = qu.top().second;
    qu.pop();
    for (int i = 0; i < tab[act].size(); i++) {
      int bct = tab[act][i].first;
      long long r = tab[act][i].second;
      if (dist[bct] > dist[act] + r) {
        dist[bct] = dist[act] + r;
        qu.push(make_pair(dist[bct], bct));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> m;
  cin >> x >> y;
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  for (int i = 1; i <= n; i++) {
    dist[i] = 1000000000000000001;
    cin >> mdist[i] >> cost[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      visited[j] = 0;
    }
    dfs(i, mdist[i], i);
  }
  dist[x] = 0;
  dijk(x);
  if (dist[y] < 1000000000000000001)
    cout << dist[y] << "\n";
  else
    cout << -1 << "\n";
  return 0;
}
