#include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j, k;
int tmp1, tmp2;
int s, e;
int t[1005], c[1005];
long long inf;
long long dis[1005];
long long ad[1005][1005];
int u[1005], v[1005], w[1005];
set<pair<long long, int> > S;
set<pair<long long, int> >::iterator it1, it2;
vector<pair<long long, int> > V[1005];
vector<pair<long long, int> >::iterator it;
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d %d", &s, &e);
  s--;
  e--;
  inf = 1000000000;
  inf = inf * inf;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      ad[i][j] = inf;
    }
    ad[i][i] = 0;
  }
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &u[i], &v[i], &w[i]);
    u[i]--;
    v[i]--;
    V[u[i]].push_back(pair<long long, int>(w[i], v[i]));
    V[v[i]].push_back(pair<long long, int>(w[i], u[i]));
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      ad[i][j] = inf;
    }
    ad[i][i] = 0;
    S.insert(pair<long long, int>(0, i));
    while (!S.empty()) {
      it1 = S.begin();
      tmp1 = it1->second;
      S.erase(it1);
      for (it = V[tmp1].begin(); it != V[tmp1].end(); it++) {
        if (ad[i][it->second] > ad[i][tmp1] + it->first) {
          S.erase(pair<int, int>(ad[i][it->second], it->second));
          ad[i][it->second] = ad[i][tmp1] + it->first;
          S.insert(pair<int, int>(ad[i][it->second], it->second));
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    scanf("%d %d", &t[i], &c[i]);
    V[i].clear();
    for (j = 0; j < n; j++) {
      if (ad[i][j] <= t[i]) {
        V[i].push_back(pair<long long, int>((long long)c[i], j));
      }
    }
    dis[i] = inf;
  }
  dis[s] = 0;
  S.insert(pair<long long, int>(0, s));
  while (!S.empty()) {
    it1 = S.begin();
    tmp1 = it1->second;
    S.erase(it1);
    for (it = V[tmp1].begin(); it != V[tmp1].end(); it++) {
      if (dis[it->second] > dis[tmp1] + it->first) {
        S.erase(pair<int, int>(dis[it->second], it->second));
        dis[it->second] = dis[tmp1] + it->first;
        S.insert(pair<int, int>(dis[it->second], it->second));
      }
    }
  }
  if (dis[e] != inf)
    cout << dis[e] << endl;
  else
    cout << "-1" << endl;
  return 0;
}
