#include <bits/stdc++.h>
using namespace std;
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
long long rll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
long long mas[2][1005][1005];
long long dp[1005];
long long ans = 2000000000000000;
int start, finish;
vector<vector<pair<int, long long>>> graph;
void solve() {
  int n = ri(), m = ri();
  start = ri(), finish = ri();
  graph.resize(n + 1);
  for (int i = (int)(1); i <= (int)(m); i++) {
    int a = ri(), b = ri();
    long long c;
    cin >> c;
    graph[a].push_back(make_pair(b, c));
    graph[b].push_back(make_pair(a, c));
  }
  priority_queue<pair<long long, int>> st;
  for (int i = (int)(1); i <= (int)(1000); i++)
    for (int j = (int)(1); j <= (int)(1000); j++)
      mas[1][i][j] = mas[0][i][j] = 2000000000000000;
  for (int i = (int)(1); i <= (int)(n); i++) {
    long long a, b;
    cin >> a >> b;
    st.push(make_pair(a, i));
    while (!st.empty()) {
      pair<long long, int> x = st.top();
      st.pop();
      if (x.first < 0) continue;
      if (mas[0][i][x.second] <= x.first) continue;
      mas[0][i][x.second] = x.first;
      if (mas[1][i][x.second] > b)
        mas[1][i][x.second] = b;
      else
        continue;
      for (int j = (int)(0); j <= (int)(graph[x.second].size() - 1); j++)
        if (graph[x.second][j].second <= x.first &&
            mas[0][i][graph[x.second][j].first] >
                graph[x.second][j].second - x.first)
          st.push(make_pair(x.first - graph[x.second][j].second,
                            graph[x.second][j].first));
    }
  }
  for (int i = (int)(1); i <= (int)(1000); i++) dp[i] = 2000000000000000;
  set<pair<long long, int>> st1;
  st1.insert(make_pair(0, start));
  while (!st1.empty()) {
    pair<long long, int> x;
    x.first = st1.begin()->first;
    x.second = st1.begin()->second;
    st1.erase(st1.begin());
    if (dp[x.second] < x.first) continue;
    dp[x.second] = x.first;
    for (int i = (int)(1); i <= (int)(n); i++)
      if (mas[1][x.second][i] && dp[i] > dp[x.second] + mas[1][x.second][i]) {
        st1.erase(make_pair(dp[i], i));
        dp[i] = dp[x.second] + mas[1][x.second][i];
        st1.insert(make_pair(dp[i], i));
      }
  }
  if (dp[finish] >= 2000000000000000)
    cout << -1 << endl;
  else
    cout << dp[finish];
}
int main() {
  solve();
  return 0;
}
