#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > taxi;
vector<pair<int, int> > g[1005];
vector<int> ng[1005];
set<pair<long long, int> > second;
int n, m;
void makeNewGraph(int v) {
  long long d[1005];
  for (int i = 0; i < n; i++) d[i] = 10000000000000000ll;
  d[v] = 0;
  second.insert(make_pair(d[v], v));
  int strt = v;
  while (!second.empty()) {
    v = (*second.begin()).second;
    second.erase(second.begin());
    for (int i = 0; i < g[v].size(); i++)
      if (d[g[v][i].first] > d[v] + g[v][i].second &&
          d[v] + g[v][i].second <= taxi[strt].first) {
        second.erase(make_pair(d[g[v][i].first], g[v][i].first));
        d[g[v][i].first] = d[v] + g[v][i].second;
        second.insert(make_pair(d[g[v][i].first], g[v][i].first));
      }
  }
  for (int i = 0; i < n; i++)
    if (d[i] != 0 && d[i] <= taxi[strt].first) ng[strt].push_back(i);
}
long long dijkstra(int v, int u) {
  long long d[1005];
  for (int i = 0; i < n; i++) d[i] = 10000000000000000ll;
  d[v] = 0;
  second.insert(make_pair(d[v], v));
  while (!second.empty()) {
    v = (*second.begin()).second;
    second.erase(second.begin());
    for (int i = 0; i < ng[v].size(); i++)
      if (d[ng[v][i]] > d[v] + taxi[v].second) {
        second.erase(make_pair(d[ng[v][i]], ng[v][i]));
        d[ng[v][i]] = d[v] + taxi[v].second;
        second.insert(make_pair(d[ng[v][i]], ng[v][i]));
      }
  }
  if (d[u] == 10000000000000000ll) return -1;
  return d[u];
}
int main() {
  int v, u, w, x, y;
  cin >> n >> m >> x >> y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &v, &u, &w);
    g[v - 1].push_back(make_pair(u - 1, w));
    g[u - 1].push_back(make_pair(v - 1, w));
  }
  int ti, ci;
  taxi.resize(n + 1);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &ti, &ci);
    taxi[i] = make_pair(ti, ci);
  }
  for (int i = 0; i < n; i++) makeNewGraph(i);
  cout << dijkstra(x - 1, y - 1);
  return 0;
}
