#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  for (int(i) = 0; (i) < (t.size()); ++(i)) s << t[i] << " ";
  return s;
}
const long long infty = 1000000000000000000LL;
int n;
long long ww[1006][1006];
int acts;
struct cmp {
  bool operator()(const int &a, const int &b) const {
    if (ww[acts][a] < ww[acts][b]) return true;
    if (ww[acts][a] > ww[acts][b]) return false;
    return a < b;
  }
};
void dijkstra(int s, vector<pair<int, long long> > *adj) {
  for (int(i) = 0; (i) < (n + 1); ++(i)) ww[s][i] = infty;
  acts = s;
  ww[s][s] = 0;
  set<int, cmp> kopiec;
  for (int i = 0; i <= n; i++) kopiec.insert(i);
  while (!kopiec.empty()) {
    int u = *(kopiec.begin());
    kopiec.erase(kopiec.begin());
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].first;
      long long c = adj[u][i].second;
      if (ww[s][u] + c < ww[s][v]) {
        kopiec.erase(kopiec.find(v));
        ww[s][v] = ww[s][u] + c;
        kopiec.insert(v);
      }
    }
  }
}
vector<pair<int, long long> > adj1[1006], adj2[1006];
int main() {
  int(nn), (m);
  scanf("%d %d", &(nn), &(m));
  int(x), (y);
  scanf("%d %d", &(x), &(y));
  for (int(i) = 0; (i) < (m); ++(i)) {
    int(a), (b), (c);
    scanf("%d %d %d", &(a), &(b), &(c));
    adj1[a].push_back(make_pair(b, c));
    adj1[b].push_back(make_pair(a, c));
  }
  n = nn;
  for (int(i) = 1; (i) <= (n); ++(i)) dijkstra(i, adj1);
  for (int(i) = 1; (i) <= (n); ++(i)) {
    int(ti), (ci);
    scanf("%d %d", &(ti), &(ci));
    for (int(j) = 1; (j) <= (n); ++(j))
      if (i != j) {
        if (ww[i][j] <= ti) {
          adj2[i].push_back(make_pair(j, ci));
        }
      }
  }
  dijkstra(x, adj2);
  if (ww[x][y] == infty)
    printf("-1\n");
  else
    cout << ww[x][y] << endl;
}
