#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
vector<pair<int, int> > e[maxn];
vector<pair<int, int> > ee[maxn];
void dejkstra1(int s, const int &T, const int &C, const int &N) {
  vector<long long> d(N, 1LL << 60);
  d[s] = 0;
  priority_queue<pair<int, int> > q;
  q.push(make_pair(0, s));
  while (q.size()) {
    const int v = q.top().second;
    const int cost = -q.top().first;
    q.pop();
    if (cost > d[v]) continue;
    for (int _n(e[v].size()), i(0); i < _n; i++) {
      const int to = e[v][i].first;
      const int len = e[v][i].second;
      if (d[to] > d[v] + len && d[v] + len <= T) {
        d[to] = d[v] + len;
        q.push(make_pair(-d[to], to));
      }
    }
  }
  for (int _n(N), i(0); i < _n; i++)
    if (i != s) {
      if (d[i] < (1LL << 60)) ee[s].push_back(make_pair(i, C));
    }
}
long long dejkstra2(int s, int t, int n) {
  vector<int> used(n, 0);
  vector<long long> d(n, 1LL << 60);
  d[s] = 0;
  for (;;) {
    int v = -1;
    for (int _n(n), i(0); i < _n; i++)
      if (!used[i] && (v == -1 || d[i] < d[v])) v = i;
    if (v == -1) return -1;
    if (d[v] == (1LL << 60)) return -1;
    if (v == t) return d[t];
    used[v] = true;
    for (int _n(ee[v].size()), i(0); i < _n; i++) {
      const int to = ee[v][i].first;
      const int cost = ee[v][i].second;
      if (d[to] > d[v] + cost) {
        d[to] = d[v] + cost;
      }
    }
  }
  return -1;
}
int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  --s, --t;
  for (int _n(m), i(0); i < _n; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    --x, --y;
    e[x].push_back(make_pair(y, w));
    e[y].push_back(make_pair(x, w));
  }
  for (int _n(n), i(0); i < _n; i++) {
    int t, c;
    cin >> t >> c;
    dejkstra1(i, t, c, n);
  }
  cout << dejkstra2(s, t, n) << endl;
  return 0;
}
