#include <bits/stdc++.h>
using namespace std;
const long long maxn = 10010, inf = 99999999999999999ll;
vector<long long> adj[maxn], adj2[maxn], cst[maxn];
set<pair<long long, int> > st;
long long arr[maxn], t[maxn], c[maxn];
bool mark[maxn];
int main() {
  int n, m, u, v, l, s, y;
  cin >> n >> m >> s >> y;
  s--;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> l;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    cst[u].push_back(l);
    cst[v].push_back(l);
  }
  for (int i = 0; i < n; i++) cin >> t[i] >> c[i];
  for (int i = 0; i < n; i++) {
    st.clear();
    st.insert(make_pair(0, i));
    fill(arr, arr + maxn, inf);
    fill(mark, mark + maxn, false);
    for (int j = 0; j < n; j++)
      if (j != i) st.insert(make_pair(inf, j));
    long long len = 0;
    while (!st.empty()) {
      int x = st.begin()->second;
      len = st.begin()->first;
      st.erase(st.begin());
      mark[x] = true;
      for (int i = 0; i < adj[x].size(); i++) {
        int next = adj[x][i];
        if (!mark[next] && arr[next] > len + cst[x][i]) {
          st.erase(make_pair(arr[next], next));
          arr[next] = len + cst[x][i];
          st.insert(make_pair(arr[next], next));
        }
      }
    }
    for (int j = 0; j < n; j++) {
      if (arr[j] <= t[i]) adj2[i].push_back(j);
    }
  }
  fill(arr, arr + maxn, inf);
  fill(mark, mark + maxn, false);
  st.clear();
  st.insert(make_pair(0, s));
  for (int i = 0; i < n; i++)
    if (i != s) st.insert(make_pair(inf, i));
  arr[s] = 0;
  long long len = 0;
  while (!st.empty()) {
    int x = st.begin()->second;
    len = st.begin()->first;
    st.erase(st.begin());
    mark[x] = true;
    for (int i = 0; i < adj2[x].size(); i++) {
      int next = adj2[x][i];
      if (!mark[next] && arr[next] > len + c[x]) {
        st.erase(make_pair(arr[next], next));
        arr[next] = len + c[x];
        st.insert(make_pair(arr[next], next));
      }
    }
  }
  if (arr[y - 1] != inf)
    cout << arr[y - 1] << endl;
  else
    cout << -1 << endl;
}
