#include <bits/stdc++.h>
using namespace std;
int N, Z, M, x, y, u, v, ww;
long long w[2005];
int _c[1005], _t[1005];
long long cc[1005], tt[1005];
long long d[1005];
int gnt[1005];
int t[2005];
int nt[2005];
int q[1000000], qh, qt;
long long dd[1005][1005];
bool inq[1005];
void SPFA(int x) {
  memset(inq, 0, sizeof(inq));
  qh = qt = 0;
  q[0] = x;
  while (qh <= qt) {
    int u = q[qh];
    qh++;
    inq[u] = 0;
    for (int i = gnt[u]; i != -1; i = nt[i]) {
      if (dd[x][t[i]] > dd[x][u] + w[i]) {
        dd[x][t[i]] = dd[x][u] + w[i];
        if (!inq[t[i]]) {
          q[++qt] = t[i];
          inq[t[i]] = 1;
        }
      }
    }
  }
}
void SPFA2() {
  memset(inq, 0, sizeof(inq));
  qh = qt = 0;
  q[0] = x;
  while (qh <= qt) {
    int u = q[qh];
    qh++;
    inq[u] = 0;
    for (int i = 1; i <= N; ++i) {
      if (dd[u][i] <= tt[u] && d[i] > d[u] + cc[u]) {
        d[i] = d[u] + cc[u];
        if (!inq[i]) {
          q[++qt] = i;
          inq[i] = 1;
        }
      }
    }
  }
}
int main() {
  scanf("%d%d%d%d", &N, &Z, &x, &y);
  for (int i = 1; i <= N; ++i) gnt[i] = -1;
  while (Z--) {
    scanf("%d%d%d", &u, &v, &ww);
    t[M] = v;
    nt[M] = gnt[u];
    w[M] = ww;
    gnt[u] = M++;
    t[M] = u;
    nt[M] = gnt[v];
    w[M] = ww;
    gnt[v] = M++;
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d%d", &_t[i], &_c[i]);
    tt[i] = _t[i];
    cc[i] = _c[i];
  }
  for (int i = 1; i <= N; ++i) {
    d[i] = 100000000000000000LL;
    for (int j = 1; j <= N; ++j) {
      dd[i][j] = 100000000000000000LL;
    }
    dd[i][i] = 0;
    SPFA(i);
  }
  d[x] = 0;
  SPFA2();
  if (d[y] == 100000000000000000LL)
    puts("-1");
  else {
    cout << d[y] << endl;
  }
  return 0;
}
