#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
bool used[1005];
int n, m, s, t;
long long d[1005], ds[1005][1005], g[1005][1005];
pair<int, int> taxi[1005];
vector<pair<int, long long> > gr[1005], _gr[1005];
inline void dijkstra(int s) {
  set<pair<int, long long> > st;
  st.insert(make_pair(s, d[s]));
  while (!st.empty()) {
    int v = st.begin()->first;
    st.erase(st.begin());
    if (d[v] == inf) return;
    for (int j = 0; j < (int)gr[v].size(); j++) {
      int to = gr[v][j].first;
      long long len = gr[v][j].second;
      if (d[v] + len < d[to]) {
        st.erase(make_pair(to, d[to]));
        d[to] = d[v] + len;
        st.insert(make_pair(to, d[to]));
      }
    }
  }
}
inline void dijkstra2() {
  int v;
  for (int i = 0; i < n; i++) {
    v = -1;
    for (int j = 0; j < n; j++)
      if (!used[j] && (v == -1 || d[v] > d[j])) v = j;
    if (v == -1 || d[v] == inf) return;
    used[v] = 1;
    for (vector<pair<int, long long> >::iterator vit = _gr[v].begin();
         vit != _gr[v].end(); vit++)
      if (d[vit->first] > d[v] + vit->second)
        d[vit->first] = d[v] + vit->second;
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t), s--, t--;
  for (int i = 0; i < m; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w), x--, y--;
    gr[x].push_back(make_pair(y, w));
    gr[y].push_back(make_pair(x, w));
  }
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &taxi[i].first, &taxi[i].second);
  }
  for (int i = 0; i < n; i++) {
    fill(d, d + n, inf);
    d[i] = 0;
    dijkstra(i);
    for (int j = 0; j < n; j++) ds[i][j] = d[j];
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j && ds[i][j] <= taxi[i].first)
        _gr[i].push_back(make_pair(j, taxi[i].second));
  fill(d, d + n, inf);
  d[s] = 0;
  dijkstra2();
  printf("%I64d\n", d[t] == inf ? -1 : d[t]);
  return 0;
}
