#include <bits/stdc++.h>
using namespace std;
int n, m;
int sx, ex;
vector<pair<long, long> > g[1001];
long long dis[1001][1001];
priority_queue<pair<long long, long long> > q;
const long long INF = 1e18;
pair<int, int> taxi[1001];
void find_path(int x) {
  q.push({0, x});
  dis[x][x] = 0;
  while (!q.empty()) {
    long long d1, d2;
    pair<long long, long long> now = q.top();
    q.pop();
    d1 = -now.first, d2 = now.second;
    if (d1 != dis[x][d2]) continue;
    for (int i = 0; i < g[d2].size(); i++) {
      long long D1 = g[d2][i].first, D2 = g[d2][i].second;
      if (dis[x][D1] > d1 + D2) {
        dis[x][D1] = d1 + D2;
        q.push({-dis[x][D1], D1});
      }
    }
  }
}
int main() {
  cin >> n >> m >> sx >> ex;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    g[x].push_back({y, z});
    g[y].push_back({x, z});
  }
  for (int i = 0; i < n + 1; i++)
    for (int j = 0; j < n + 1; j++) dis[i][j] = INF;
  for (int i = 1; i <= n; i++) find_path(i);
  vector<int> v;
  memset(g, 0, sizeof(g));
  for (int i = 1; i <= n; i++) {
    cin >> taxi[i].first >> taxi[i].second;
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (dis[i][j] <= taxi[i].first) g[i].push_back({j, taxi[i].second});
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) dis[i][j] = INF;
  find_path(sx);
  if (sx == ex) {
    cout << 0 << endl;
    return 0;
  }
  if (dis[sx][ex] != INF)
    cout << dis[sx][ex] << endl;
  else
    cout << -1 << endl;
  return 0;
}
