#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
long long par[maxn], t[maxn], c[maxn];
const long long inf = 1000000000000ll;
long long dist[maxn][maxn], dis[maxn];
bool mark[maxn];
vector<int> v[maxn], u[maxn];
set<pair<long long, int> > s;
vector<long long> cost1[maxn], cost2[maxn];
int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  x--;
  y--;
  for (int i = 0; i < m; i++) {
    int a, b, z;
    cin >> a >> b >> z;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
    cost1[a].push_back(z);
    cost1[b].push_back(z);
  }
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> c[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) dist[i][j] = inf;
  }
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) mark[k] = 0;
    dist[i][i] = 0;
    s.insert(make_pair(0, i));
    while (!s.empty()) {
      int cur = s.begin()->second;
      s.erase(s.begin());
      mark[cur] = true;
      for (int j = 0; j < v[cur].size(); j++) {
        int next = v[cur][j];
        if (mark[next] == true) continue;
        long long ndist = dist[i][cur] + cost1[cur][j];
        if (dist[i][next] > ndist) {
          par[next] = cur;
          s.erase(make_pair(dist[i][next], next));
          dist[i][next] = min(ndist, dist[i][next]);
          s.insert(make_pair(dist[i][next], next));
        }
      }
    }
  }
  for (int i = 0; i < n; i++) mark[i] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dist[i][j] > 0 && dist[i][j] <= t[i]) {
        u[i].push_back(j);
        cost2[i].push_back(c[i]);
      }
    }
  }
  for (int i = 0; i < n; i++) dis[i] = inf;
  dis[x] = 0;
  s.insert(make_pair(0, x));
  while (!s.empty()) {
    int cur = s.begin()->second;
    s.erase(s.begin());
    mark[cur] = true;
    for (int i = 0; i < u[cur].size(); i++) {
      int next = u[cur][i];
      if (mark[next] == true) continue;
      long long ndist = dis[cur] + cost2[cur][i];
      if (dis[next] > ndist) {
        s.erase(make_pair(dis[next], next));
        dis[next] = min(ndist, dis[next]);
        s.insert(make_pair(dis[next], next));
      }
    }
  }
  if (mark[y] == true)
    cout << dis[y];
  else
    cout << -1;
  return 0;
}
