#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 61;
template <class T>
struct Edge {
  int u, v;
  T w;
  Edge(int U, int V, T W) : u(U), v(V), w(W) {}
};
template <class T>
struct AdjList : public vector<vector<Edge<T> > > {
  AdjList(int n, const vector<Edge<T> > &v = vector<Edge<T> >())
      : vector<vector<Edge<T> > >(n, v) {}
};
template <class T>
void Dijkstra(const AdjList<T> &adj, int s, vector<T> &d) {
  int n = adj.size();
  d.assign(n, INF);
  d[s] = 0;
  priority_queue<pair<T, int> > pq;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    pair<T, int> a = pq.top();
    pq.pop();
    int u = a.second;
    if (d[u] < -a.first) continue;
    for (int i = 0; i < (adj[u].size()); i++) {
      int v = adj[u][i].v;
      T w = adj[u][i].w;
      if (d[u] + w < d[v]) {
        d[v] = d[u] + w;
        pq.push(make_pair(-d[v], v));
      }
    }
  }
}
int main() {
  int n, m, s, g;
  scanf("%d%d%d%d", &n, &m, &s, &g);
  s--, g--;
  AdjList<long long> adj(n);
  for (int i = 0; i < (m); i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--, v--;
    adj[u].push_back(Edge<long long>(u, v, w));
    adj[v].push_back(Edge<long long>(v, u, w));
  }
  vector<long long> d;
  AdjList<long long> adj2(n);
  for (int u = 0; u < (n); u++) {
    int t, c;
    scanf("%d%d", &t, &c);
    Dijkstra(adj, u, d);
    for (int v = 0; v < (n); v++)
      if (d[v] <= t) adj2[u].push_back(Edge<long long>(u, v, c));
  }
  Dijkstra(adj2, s, d);
  printf("%I64d\n", d[g] < INF ? d[g] : -1);
  return 0;
}
