#include <bits/stdc++.h>
const long long infinity = 1ll * 1000 * 1000 * 1000 * 1000 * 1000;
struct Link {
  long long vertex;
  long long cost;
  Link() {}
  Link(long long v, long long c) : vertex(v), cost(c) {}
  operator long long() const { return vertex; }
};
void dijkstra(const std::vector<std::vector<Link> >& graph, long long vertex,
              std::vector<long long>& distance) {
  distance[vertex] = 0;
  std::set<std::pair<long long, long long> > queue;
  queue.insert(std::make_pair(distance[vertex], vertex));
  while (!queue.empty()) {
    long long current = queue.begin()->second;
    for (long long i = 0; i < graph[current].size(); i++) {
      if (distance[graph[current][i]] >
          distance[current] + graph[current][i].cost) {
        queue.erase(
            std::make_pair(distance[graph[current][i]], graph[current][i]));
        distance[graph[current][i]] =
            std::min(distance[graph[current][i]],
                     distance[current] + graph[current][i].cost);
        queue.insert(
            std::make_pair(distance[graph[current][i]], graph[current][i]));
      }
    }
    queue.erase(queue.begin());
  }
}
void buildRealGraph(const std::vector<std::vector<Link> >& graph,
                    std::vector<std::vector<Link> >& real,
                    const std::vector<long long>& length,
                    const std::vector<long long>& cost) {
  for (long long i = 0; i < graph.size(); i++) {
    std::vector<long long> distance(graph.size(), infinity);
    dijkstra(graph, i, distance);
    for (long long j = 0; j < graph.size(); j++)
      if (distance[j] <= length[i]) real[i].push_back(Link(j, cost[i]));
  }
}
int main() {
  long long n, m, x, y;
  std::cin >> n >> m >> x >> y;
  std::vector<std::vector<Link> > graph(n);
  for (long long i = 0; i < m; i++) {
    long long u, v, l;
    std::cin >> u >> v >> l;
    graph[u - 1].push_back(Link(v - 1, l));
    graph[v - 1].push_back(Link(u - 1, l));
  }
  std::vector<long long> length(graph.size());
  std::vector<long long> cost(graph.size());
  for (long long i = 0; i < graph.size(); i++) std::cin >> length[i] >> cost[i];
  std::vector<std::vector<Link> > real(graph.size());
  buildRealGraph(graph, real, length, cost);
  std::vector<long long> answer(graph.size(), infinity);
  dijkstra(real, x - 1, answer);
  std::cout << (answer[y - 1] < infinity ? answer[y - 1] : -1) << std::endl;
}
