#include <bits/stdc++.h>
using namespace std;
class NODE {
 public:
  int i;
  long long cost;
} cur, tn;
bool operator<(const NODE &a, const NODE &b) {
  if (a.cost != b.cost) return a.cost < b.cost;
  return a.i < b.i;
}
multiset<NODE> ss;
multiset<NODE>::iterator it;
long long path[1005][1005];
bool flag[1005];
int n, es;
int from, to;
int mat[1005][1005];
vector<vector<int> > ed;
vector<vector<int> > cost;
int ns[1005];
void dijkstra(int ind) {
  int c, c2;
  ss.clear();
  memset(flag, 0, sizeof(flag));
  for (c = 0; c < n; c++) path[ind][c] = 1LL << 59;
  flag[ind] = 1;
  path[ind][ind] = 0;
  tn.i = ind;
  tn.cost = 0;
  ss.insert(tn);
  while (1) {
    if (ss.size() == 0) break;
    it = ss.begin();
    cur = *it;
    ss.erase(it);
    flag[cur.i] = 1;
    for (c = 0; c < ns[cur.i]; c++) {
      int i2 = ed[cur.i][c];
      if (flag[i2]) continue;
      if (path[ind][i2] > path[ind][cur.i] + (long long)cost[cur.i][c]) {
        tn.i = i2;
        tn.cost = path[ind][i2];
        it = ss.find(tn);
        if (it != ss.end()) ss.erase(it);
        tn.cost = path[ind][i2] = path[ind][cur.i] + (long long)cost[cur.i][c];
        ss.insert(tn);
      }
    }
  }
  return;
}
void getdists() {
  int c, c2;
  for (c = 0; c < n; c++) dijkstra(c);
  return;
}
long long ans[1005];
int maxlen[1005], salary[1005];
void solve() {
  int c, c2;
  memset(flag, 0, sizeof(flag));
  for (c = 0; c < n; c++) ans[c] = 1LL << 59;
  ans[from] = 0;
  while (1) {
    int i = -1;
    long long mi = 1LL << 59;
    for (c = 0; c < n; c++) {
      if (flag[c]) continue;
      if (ans[c] >= 1LL << 59) continue;
      if (ans[c] < mi) {
        mi = ans[c];
        i = c;
      }
    }
    if (i == -1) break;
    flag[i] = 1;
    for (c = 0; c < n; c++) {
      if (flag[c]) continue;
      if (path[i][c] > (long long)maxlen[i]) continue;
      ans[c] = min(ans[c], ans[i] + (long long)salary[i]);
    }
  }
  return;
}
int main() {
  FILE *in = stdin;
  int c, c2;
  fscanf(in, "%d%d", &n, &es);
  fscanf(in, "%d%d", &from, &to);
  from--;
  to--;
  ed.resize(n);
  cost.resize(n);
  for (c = 0; c < n; c++)
    for (c2 = 0; c2 < n; c2++) mat[c][c2] = 2000500000;
  for (c = 0; c < es; c++) {
    int t1, t2, t3;
    fscanf(in, "%d%d%d", &t1, &t2, &t3);
    t1--;
    t2--;
    mat[t1][t2] = min(t3, mat[t1][t2]);
    mat[t2][t1] = mat[t1][t2];
    ed[t1].push_back(t2);
    ed[t2].push_back(t1);
    cost[t1].push_back(t3);
    cost[t2].push_back(t3);
    ns[t1]++;
    ns[t2]++;
  }
  for (c = 0; c < n; c++) fscanf(in, "%d%d", &maxlen[c], &salary[c]);
  getdists();
  solve();
  if (ans[to] == 1LL << 59)
    printf("-1\n");
  else
    printf("%I64d\n", ans[to]);
  return 0;
}
