#include <bits/stdc++.h>
using namespace std;
const int inf = 168430090;
struct edge {
  int v, next;
  long long w;
} a[15000];
int start[1200], tot = 0;
inline void addedge(int u, int v, int w) {
  a[tot].v = v;
  a[tot].w = (long long)w;
  a[tot].next = start[u];
  start[u] = tot++;
}
int n, m;
long long g[1100][1100];
bool minn(long long x, long long y) {
  if (x == -1) return 0;
  return x < y;
}
void u(long long &x, long long y) {
  if (x == -1 || x > y) x = y;
}
void allshort() {
  int i, j, k;
  for (i = 0; i < 1100; i++)
    for (j = 0; j < 1100; j++) {
      if (i == j)
        g[i][i] = 0;
      else
        g[i][j] = 1LL << 60;
    }
  for (i = 1; i <= n; i++) {
    queue<int> q;
    q.push(i);
    bool que[1200] = {0};
    que[i] = 1;
    g[i][i] = 0;
    while (!q.empty()) {
      int tmp = q.front();
      q.pop();
      que[tmp] = 0;
      for (j = start[tmp]; ~j; j = a[j].next) {
        if (g[i][a[j].v] > g[i][tmp] + a[j].w) {
          g[i][a[j].v] = g[i][tmp] + a[j].w;
          if (!que[a[j].v]) {
            q.push(a[j].v);
            que[a[j].v] = 1;
          }
        }
      }
    }
  }
}
long long t[1111], c[1111];
long long d[1111];
int main() {
  int i, j, k;
  memset(start, -1, sizeof(start));
  tot = 0;
  int s, ed;
  scanf("%d%d%d%d", &n, &m, &s, &ed);
  for (i = 0; i < m; i++) {
    int q, w, e;
    scanf("%d%d%d", &q, &w, &e);
    addedge(q, w, e);
    addedge(w, q, e);
  }
  allshort();
  for (i = 1; i <= n; i++) {
    int q, w;
    scanf("%d%d", &q, &w);
    t[i] = q;
    c[i] = w;
  }
  bool v[1111] = {0};
  for (i = 1; i <= n; i++) {
    d[i] = -1;
    v[i] = 0;
  }
  d[s] = 0;
  int ccc;
  for (ccc = 0; ccc < n; ccc++) {
    long long mi = 1LL << 49, pos;
    for (i = 1; i <= n; i++) {
      if (!v[i] && minn(d[i], mi)) {
        mi = d[i];
        pos = i;
      }
    }
    v[pos] = 1;
    for (i = 1; i <= n; i++) {
      if (v[i]) continue;
      if (g[pos][i] <= t[pos]) {
        u(d[i], d[pos] + c[pos]);
      }
    }
  }
  if (d[ed] > (1LL << 41)) d[ed] = -1;
  cout << d[ed] << endl;
  return 0;
}
