#include <bits/stdc++.h>
using namespace std;
struct node {
  int next, di;
  node() {}
  node(int a, int b) : next(a), di(b) {}
  bool operator<(node p1) const { return di > p1.di; }
};
vector<node> ady_list[1005];
vector<node> ady_list2[1005];
int main() {
  int n, m, ini, fin, u, v, d;
  int dis, cost;
  long long int dist[1005];
  scanf("%d %d", &n, &m);
  scanf("%d %d", &ini, &fin);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &u, &v, &d);
    ady_list[u - 1].push_back(node(v - 1, d));
    ady_list[v - 1].push_back(node(u - 1, d));
  }
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &dis, &cost);
    priority_queue<node> pq;
    pq.push(node(i, 0));
    for (int j = 0; j < n + 1; j++) dist[j] = (((1LL << 62) - 1) << 1) + 1;
    dist[i] = 0LL;
    while (!pq.empty()) {
      node aux = pq.top();
      pq.pop();
      int u = aux.next, d = aux.di;
      if (d <= dist[u]) {
        for (int k = 0; k < ady_list[u].size(); k++) {
          node aux2 = ady_list[u][k];
          int v = aux2.next, w = aux2.di;
          if (dist[u] + w < dist[v]) {
            dist[v] = dist[u] + w;
            pq.push(node(v, dist[v]));
          }
        }
      }
    }
    for (int j = 0; j < n; j++) {
      if (i != j && dist[j] <= dis) {
        ady_list2[i].push_back(node(j, cost));
      }
    }
  }
  priority_queue<node> pq;
  pq.push(node(ini - 1, 0));
  for (int j = 0; j < n + 1; j++) dist[j] = (((1LL << 62) - 1) << 1) + 1;
  dist[ini - 1] = 0LL;
  while (!pq.empty()) {
    node aux = pq.top();
    pq.pop();
    int u = aux.next, d = aux.di;
    if (d <= dist[u]) {
      for (int i = 0; i < ady_list2[u].size(); i++) {
        node aux2 = ady_list2[u][i];
        int v = aux2.next, w = aux2.di;
        if (dist[u] + w < dist[v]) {
          dist[v] = dist[u] + w;
          pq.push(node(v, dist[v]));
        }
      }
    }
  }
  if (dist[fin - 1] >= (((1LL << 62) - 1) << 1) + 1)
    printf("-1\n");
  else
    printf("%I64d\n", dist[fin - 1]);
  return 0;
}
