#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;
const long long INF = 1e18;
int n, m, x, y;
int head[maxn], to[maxn], nx[maxn], ppp = 0;
long long t[maxn];
long long c[maxn];
long long cost[maxn];
vector<pair<int, long long> > edge[maxn];
void add_edge(int u, int v, long long val) {
  to[ppp] = v, nx[ppp] = head[u], cost[ppp] = val, head[u] = ppp++;
  swap(u, v);
  to[ppp] = v, nx[ppp] = head[u], cost[ppp] = val, head[u] = ppp++;
}
long long dis[maxn];
void spfa(int s) {
  fill(dis, dis + maxn, INF);
  dis[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = nx[i]) {
      int v = to[i];
      if (dis[v] > dis[u] + cost[i]) {
        dis[v] = dis[u] + cost[i];
        q.push(v);
      }
    }
  }
}
void spfa2() {
  fill(dis, dis + maxn, INF);
  dis[x] = 0;
  queue<int> q;
  q.push(x);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < edge[u].size(); i++) {
      int v = edge[u][i].first;
      if (dis[v] > dis[u] + edge[u][i].second) {
        dis[v] = dis[u] + edge[u][i].second;
        q.push(v);
      }
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  ppp = 0;
  cin >> n >> m;
  cin >> x >> y;
  while (m--) {
    int u, v;
    long long val;
    cin >> u >> v >> val;
    add_edge(u, v, val);
  }
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    spfa(i);
    for (int j = 1; j <= n; j++) {
      if (i != j && dis[j] <= t[i]) {
        edge[i].push_back(pair<int, long long>(j, c[i]));
      }
    }
  }
  spfa2();
  if (dis[y] == INF)
    cout << -1 << '\n';
  else
    cout << dis[y] << '\n';
  return 0;
}
