#include <bits/stdc++.h>
using namespace std;
set<pair<long long, long long> > se;
vector<pair<long long, long long> > inp[1010], Graph[1010];
long long best[1010], inf = 1ll * 1000 * 1000 * 1000 * 1000 * 1000ll;
int n, m, c[1010], t[1010];
void up(int v) {
  for (int i = 0; i < inp[v].size(); i++) {
    pair<long long, long long> x = inp[v][i];
    if (best[v] + x.second < best[x.first]) {
      se.erase(make_pair(best[x.first], x.first));
      best[x.first] = best[v] + x.second;
      se.insert(make_pair(best[x.first], x.first));
    }
  }
}
void DIJ(int u) {
  se.clear();
  for (int i = 0; i < n; i++) {
    se.insert(make_pair(inf, i));
    best[i] = inf;
  }
  best[u] = 0;
  se.erase(make_pair(inf, u));
  se.insert(make_pair(0, u));
  pair<long long, long long> id = *se.begin();
  while (se.size() > 0 && id.first < inf) {
    up(id.second);
    se.erase(se.begin());
    id = *se.begin();
  }
}
void upG(int v) {
  for (int i = 0; i < Graph[v].size(); i++) {
    pair<long long, long long> x = Graph[v][i];
    if (best[v] + x.second < best[x.first]) {
      se.erase(make_pair(best[x.first], x.first));
      best[x.first] = best[v] + x.second;
      se.insert(make_pair(best[x.first], x.first));
    }
  }
}
void DIJG(int u) {
  se.clear();
  for (int i = 0; i < n; i++) {
    se.insert(make_pair(inf, i));
    best[i] = inf;
  }
  best[u] = 0;
  se.erase(make_pair(inf, u));
  se.insert(make_pair(0, u));
  pair<long long, long long> id = *se.begin();
  while (se.size() > 0 && id.first < inf) {
    upG(id.second);
    se.erase(se.begin());
    id = *se.begin();
  }
}
int main() {
  cin >> n >> m;
  int str, fin;
  cin >> str >> fin;
  str--, fin--;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    inp[u].push_back(make_pair(v, w));
    inp[v].push_back(make_pair(u, w));
  }
  for (int i = 0; i < n; i++) cin >> t[i] >> c[i];
  for (int i = 0; i < n; i++) {
    DIJ(i);
    for (int j = 0; j < n; j++)
      if (best[j] <= t[i] && j != i) {
        Graph[i].push_back(make_pair(j, c[i]));
      }
  }
  DIJG(str);
  if (best[fin] >= inf)
    cout << "-1";
  else
    cout << best[fin];
  return 0;
}
