#include <bits/stdc++.h>
const long long oo = 10000000000000000;
using namespace std;
long long n, m;
long long fr, to;
vector<pair<long long, long long> > v[1111];
long long dist[1111][1111];
set<pair<long long, long long> > st;
void dijkstra(long long pos) {
  for (long long i = (0); i < (n); i++)
    st.insert(make_pair(oo, i)), dist[pos][i] = oo;
  st.erase(make_pair(oo, pos));
  st.insert(make_pair(0, pos));
  dist[pos][pos] = 0;
  while (!st.empty()) {
    long long a = st.begin()->first, b = st.begin()->second;
    st.erase(st.begin());
    for (pair<long long, long long> i : v[b]) {
      if (a + i.second < dist[pos][i.first]) {
        st.erase(make_pair(dist[pos][i.first], i.first));
        dist[pos][i.first] = a + i.second;
        st.insert(make_pair(dist[pos][i.first], i.first));
      }
    }
  }
}
long long go[1111];
long long cst[1111];
vector<pair<long long, long long> > v2[1111];
long long dist2[1111];
set<pair<long long, long long> > st2;
void dijkstra2() {
  long long pos = fr;
  for (long long i = (0); i < (n); i++)
    st2.insert(make_pair(oo, i)), dist2[i] = oo;
  st2.erase(make_pair(oo, pos));
  st2.insert(make_pair(0, pos));
  dist2[pos] = 0;
  while (!st2.empty()) {
    long long a = st2.begin()->first, b = st2.begin()->second;
    st2.erase(st2.begin());
    for (pair<long long, long long> i : v2[b]) {
      if (a + i.second < dist2[i.first]) {
        st2.erase(make_pair(dist2[i.first], i.first));
        dist2[i.first] = a + i.second;
        st2.insert(make_pair(dist2[i.first], i.first));
      }
    }
  }
}
signed main() {
  cin >> n >> m;
  cin >> fr >> to;
  fr--, to--;
  for (long long i = (0); i < (m); i++) {
    long long a, b, d;
    cin >> a >> b >> d;
    v[a - 1].push_back(make_pair(b - 1, d));
    v[b - 1].push_back(make_pair(a - 1, d));
  }
  for (long long i = (0); i < (n); i++) cin >> go[i] >> cst[i];
  for (long long i = (0); i < (n); i++) dijkstra(i);
  for (long long i = (0); i < (n); i++)
    for (long long j = (0); j < (n); j++)
      if (dist[i][j] <= go[i] && i - j) v2[i].push_back(make_pair(j, cst[i]));
  dijkstra2();
  if (dist2[to] == oo)
    cout << "-1";
  else
    cout << dist2[to];
  return 0;
}
