#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 3;
const long long inf = 1e18 + 3;
vector<int> adj[maxn];
pair<int, int> tx[maxn];
vector<pair<int, int>> val[maxn];
long long dis1[maxn][maxn];
long long dis[maxn];
multiset<pair<int, int>> s;
multiset<pair<int, int>> ss[maxn];
int cur;
void dij(int u) {
  for (auto v : adj[u]) {
    if (tx[u].second + dis[u] < dis[v]) {
      s.erase({dis[v], v});
      dis[v] = dis[u] + tx[u].second;
      s.insert({dis[v], v});
    }
  }
  if (!s.size()) return;
  auto it = s.begin();
  int minn = it->second;
  s.erase(it);
  dij(minn);
}
void mg(int u) {
  for (auto v : val[u]) {
    if (dis1[cur][v.first] > dis1[cur][u] + v.second) {
      ss[cur].erase({dis1[cur][v.first], v.first});
      dis1[cur][v.first] = dis1[cur][u] + v.second;
      ss[cur].insert({dis1[cur][v.first], v.first});
    }
  }
  if (!ss[cur].size()) return;
  auto it = ss[cur].begin();
  int minn = it->second;
  ss[cur].erase(it);
  if (dis1[cur][minn] <= tx[cur].first) adj[cur].push_back(minn);
  mg(minn);
}
int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    val[u].push_back({v, w});
    val[v].push_back({u, w});
  }
  for (int i = 1; i <= n; i++) {
    int t, c;
    cin >> t >> c;
    tx[i] = {t, c};
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      if (j != i) {
        dis1[i][j] = inf;
        ss[i].insert({dis1[i][j], j});
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cur = i;
    mg(i);
  }
  fill(dis, dis + n + 1, inf);
  dis[x] = 0;
  for (int i = 1; i <= n; i++) {
    s.insert({dis[i], i});
  }
  s.erase({dis[x], x});
  dij(x);
  if (dis[y] == inf)
    cout << -1;
  else
    cout << dis[y];
  return 0;
}
