#include <bits/stdc++.h>
using namespace std;
const int INF = 2 * 0x3f3f3f3f;
const int N = 100010;
struct Node {
  vector<int> V;
  vector<int> W;
};
Node node1[N];
Node node2[N];
int dis[N], co[N];
long long dis1[N];
long long dis2[N];
int n, m;
int be, en;
void Dij1(int x) {
  int li;
  priority_queue<pair<int, int> > Q;
  dis1[x] = 0;
  Q.push(make_pair(0, x));
  while (!Q.empty()) {
    int v;
    v = Q.top().second;
    Q.pop();
    li = node1[v].V.size();
    for (int i = 0; i < li; i++) {
      if (dis1[node1[v].V[i]] < 0 ||
          dis1[node1[v].V[i]] > dis1[v] + node1[v].W[i]) {
        dis1[node1[v].V[i]] = dis1[v] + node1[v].W[i];
        Q.push(make_pair(-dis1[node1[v].V[i]], node1[v].V[i]));
      }
    }
  }
}
void Dij2() {
  int li;
  priority_queue<pair<int, int> > Q;
  dis2[be] = 0;
  Q.push(make_pair(0, be));
  while (!Q.empty()) {
    int v;
    v = Q.top().second;
    Q.pop();
    li = node2[v].V.size();
    for (int i = 0; i < li; i++) {
      if (dis2[node2[v].V[i]] < 0 ||
          dis2[node2[v].V[i]] > dis2[v] + node2[v].W[i]) {
        dis2[node2[v].V[i]] = dis2[v] + node2[v].W[i];
        Q.push(make_pair(-dis2[node2[v].V[i]], node2[v].V[i]));
      }
    }
  }
}
int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 1; i <= n; i++) {
      dis2[i] = -1;
    }
    scanf("%d%d", &be, &en);
    for (int i = 1; i <= n; i++) {
      node1[i].V.clear();
      node1[i].W.clear();
      node2[i].V.clear();
      node2[i].W.clear();
    }
    for (int i = 0; i < m; i++) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w);
      node1[u].V.push_back(v);
      node1[u].W.push_back(w);
      node1[v].V.push_back(u);
      node1[v].W.push_back(w);
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &dis[i], &co[i]);
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; j++) {
        dis1[j] = -1;
      }
      Dij1(i);
      for (int j = 1; j <= n; ++j) {
        if (i == j) {
          continue;
        }
        if (dis1[j] >= 0 && dis1[j] <= dis[i]) {
          node2[i].V.push_back(j);
          node2[i].W.push_back(co[i]);
        }
      }
    }
    Dij2();
    if (dis2[en] < 0) {
      printf("-1\n");
    } else {
      printf("%lld\n", dis2[en]);
    }
  }
}
