#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
const LL INF = (LL)1e16 + 47;
vector<vector<PII>> g;
VL dijkstra(int s) {
  set<PLL> q;
  q.emplace(0, s);
  VL d((int)g.size(), INF);
  d[s] = 0;
  while (!q.empty()) {
    auto [dd, u] = *q.begin();
    q.erase(q.begin());
    for (auto [v, w] : g[u]) {
      if (d[u] + w < d[v]) {
        q.erase({d[v], v});
        d[v] = d[u] + w;
        q.emplace(d[v], v);
      }
    }
  }
  return d;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  g.resize(n);
  int s, t;
  cin >> s >> t;
  s--;
  t--;
  for (int i = (0); i < (m); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].emplace_back(v, w);
    g[v].emplace_back(u, w);
  }
  vector<PII> taxis(n);
  for (int i = (0); i < (n); ++i) {
    cin >> taxis[i].first >> taxis[i].second;
  }
  VL cost(n, INF);
  cost[s] = 0;
  set<PLL> q;
  q.emplace(0, s);
  while (!q.empty()) {
    auto [cc, u] = *q.begin();
    q.erase(q.begin());
    auto dist = dijkstra(u);
    for (int v = (0); v < (n); ++v) {
      if (taxis[u].first >= dist[v] && cost[u] + taxis[u].second < cost[v]) {
        q.erase({cost[v], v});
        cost[v] = cost[u] + taxis[u].second;
        q.emplace(cost[v], v);
      }
    }
  }
  if (cost[t] < INF)
    cout << cost[t];
  else
    cout << -1;
  return 0;
}
