#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int next, to;
  long long w;
};
Edge *edges;
int n, m;
int st, en;
int ti[1005];
int ci[1005];
int cnt;
int head[1005];
vector<vector<long long>> dis;
void addEdge(int u, int v, long long w) {
  edges[cnt].to = v;
  edges[cnt].w = w;
  edges[cnt].next = head[u];
  head[u] = cnt++;
}
void init() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> st >> en;
  st--;
  en--;
  edges = new Edge[m * 2];
  dis.assign(n, vector<long long>(n, LLONG_MAX / 2));
  cnt = 0;
  for (int i = 0; i < int(n); i++) head[i] = -1;
  for (int i = 0; i < int(m); i++) {
    int u, v;
    long long w;
    cin >> u >> v >> w;
    u--;
    v--;
    addEdge(u, v, w);
    addEdge(v, u, w);
  }
  for (int i = 0; i < int(n); i++) cin >> ti[i] >> ci[i];
}
void dij(int s) {
  bool vis[1005];
  for (int i = 0; i < int(n); i++) vis[i] = 0;
  priority_queue<pair<long, int>, vector<pair<long, int>>,
                 greater<pair<long, int>>>
      q;
  dis[s][s] = 0;
  q.push({0, s});
  while (!q.empty()) {
    pair<long, int> a = q.top();
    q.pop();
    if (vis[a.second]) continue;
    vis[a.second] = 1;
    for (int e = head[a.second]; e != -1; e = edges[e].next) {
      int to = edges[e].to;
      long long w = edges[e].w;
      if (dis[s][to] > dis[s][a.second] + w) {
        dis[s][to] = dis[s][a.second] + w;
        q.push({dis[s][to], to});
      }
    }
  }
}
void solve() {
  init();
  for (int i = 0; i < int(n); i++) dij(i);
  edges = new Edge[n * n];
  cnt = 0;
  for (int i = 0; i < int(n); i++) head[i] = -1;
  for (int i = 0; i < int(n); i++)
    for (int j = 0; j < int(n); j++)
      if (dis[i][j] <= ti[i]) addEdge(i, j, ci[i]);
  dis[st] = vector<long long>(n, LLONG_MAX / 2);
  dij(st);
  cout << (dis[st][en] == LLONG_MAX / 2 ? -1 : dis[st][en]);
}
int main() {
  solve();
  return 0;
}
