#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0;
  char s = getchar();
  bool w = 0;
  while (s < '0' || s > '9') {
    w |= s == '-';
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  return w ? -x : x;
}
const long long inf = 1e18;
long long n, m, sx, sy, tim;
struct edge {
  long long ne, to, dis;
} e[2100], E[2100000];
struct node {
  long long t, c;
} a[2100];
long long head[2100], head1[2100000], tot, num, dis[1100];
bool vis[1100];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
inline void add(long long fr, long long to, long long dis) {
  e[++tot].ne = head[fr];
  e[tot].to = to;
  e[tot].dis = dis;
  head[fr] = tot;
}
inline void Add(long long fr, long long to, long long dis) {
  E[++num].ne = head1[fr];
  E[num].to = to;
  E[num].dis = dis;
  head1[fr] = num;
}
inline void Dij1(long long s) {
  for (long long i = 1; i <= n; i++) {
    dis[i] = inf;
    vis[i] = 0;
  }
  dis[s] = 0;
  q.push(make_pair(dis[s], s));
  while (!q.empty()) {
    long long u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (long long i = head[u]; i; i = e[i].ne) {
      long long v = e[i].to;
      if (dis[v] > dis[u] + e[i].dis && dis[u] + e[i].dis <= a[s].t) {
        dis[v] = dis[u] + e[i].dis;
        Add(s, v, a[s].c);
        if (!vis[v]) q.push(make_pair(dis[v], v));
      }
    }
  }
}
inline void Dij2(long long s) {
  for (long long i = 1; i <= n; i++) {
    dis[i] = inf;
    vis[i] = 0;
  }
  dis[s] = 0;
  q.push(make_pair(dis[s], s));
  while (!q.empty()) {
    long long u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (long long i = head1[u]; i; i = E[i].ne) {
      long long v = E[i].to;
      if (dis[v] > dis[u] + E[i].dis) {
        dis[v] = dis[u] + E[i].dis;
        if (!vis[v]) q.push(make_pair(dis[v], v));
      }
    }
  }
}
signed main() {
  n = read();
  m = read();
  sx = read();
  sy = read();
  for (long long i = 1; i <= m; i++) {
    long long u, v, w;
    u = read();
    v = read();
    w = read();
    add(u, v, w);
    add(v, u, w);
  }
  for (long long i = 1; i <= n; i++) a[i].t = read(), a[i].c = read();
  for (long long i = 1; i <= n; i++) Dij1(i);
  Dij2(sx);
  if (dis[sy] != inf)
    printf("%I64d\n", dis[sy]);
  else
    printf("-1\n");
  return 0;
}
