#include <bits/stdc++.h>
using namespace std;
int rPow(int n, int k) {
  if (k <= 0) return 1;
  return n * rPow(n, --k);
}
long long binaryNum[1000];
void decToBinary(int n) {
  long long i = 0;
  while (n > 0) {
    binaryNum[i] = n % 2;
    n = n / 2;
    i++;
  }
}
long long inf = 1000000000000000000;
vector<pair<long long, long long> > g[1001001];
vector<pair<long long, long long> > newg[1001001];
pair<long long, long long> taxis[100100];
long long dist[10010];
long long n;
void dik(long long node) {
  for (int i = 0; i < 10010; i++) dist[i] = inf;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      q;
  dist[node] = 0;
  q.push(make_pair(0, node));
  while (!q.empty()) {
    long long u = q.top().second;
    long long v = q.top().first;
    q.pop();
    if (dist[u] < v) continue;
    for (int i = 0; i < g[u].size(); i++) {
      long long nxt = g[u][i].first;
      long long w = g[u][i].second;
      if (v + w < dist[nxt]) {
        dist[nxt] = v + w;
        q.push(make_pair(dist[nxt], nxt));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dist[i] > taxis[node].first) continue;
    newg[node].push_back(make_pair(i, taxis[node].second));
  }
}
long long dik2(long long src, long long dest) {
  for (int i = 0; i < 10010; i++) dist[i] = inf;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      q;
  dist[src] = 0;
  q.push(make_pair(0, src));
  while (!q.empty()) {
    long long u = q.top().second;
    long long v = q.top().first;
    q.pop();
    if (u == dest) return v;
    if (dist[u] < v) continue;
    for (int i = 0; i < newg[u].size(); i++) {
      long long nxt = newg[u][i].first;
      long long w = newg[u][i].second;
      if (v + w < dist[nxt]) {
        dist[nxt] = v + w;
        q.push(make_pair(dist[nxt], nxt));
      }
    }
  }
  return -1;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long m;
  cin >> n >> m;
  long long x, y, a, b, w;
  cin >> x >> y;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> w;
    g[a].push_back(make_pair(b, w));
    g[b].push_back(make_pair(a, w));
  }
  long long t, c;
  for (int i = 1; i <= n; i++) {
    cin >> t >> c;
    taxis[i].first = t;
    taxis[i].second = c;
  }
  for (int i = 1; i <= n; i++) {
    dik(i);
  }
  cout << dik2(x, y) << endl;
  return 0;
}
