#include <bits/stdc++.h>
using namespace std;
int const N = 1010;
int const M = 1001000;
int n, m;
struct Graph {
  struct edges {
    int u, next;
    long long c;
  } e[M];
  int p[N], idx;
  void addedge(int u, int v, long long c) {
    e[idx].u = v, e[idx].next = p[u], e[idx].c = c, p[u] = idx++;
  }
  void init() {
    idx = 0;
    memset(p, (0xff), sizeof p);
  }
  queue<int> q;
  long long dis[N];
  bool used[N];
  void spfa(int s) {
    int t, u;
    long long w;
    while (!q.empty()) q.pop();
    memset(used, 0, sizeof used);
    for (int i = 1; i <= (n); ++i) dis[i] = 0x3FFFFFFFFFFFFFFFLL;
    dis[s] = 0;
    q.push(s);
    while (!q.empty()) {
      t = q.front();
      q.pop();
      used[t] = false;
      for (int i = p[t]; ~i; i = e[i].next) {
        u = e[i].u, w = e[i].c;
        if (dis[t] + w < dis[u]) {
          dis[u] = dis[t] + w;
          if (!used[u]) {
            used[u] = true;
            q.push(u);
          }
        }
      }
    }
  }
} g1, g2;
long long ti[N], ci[N];
int main() {
  scanf("%d%d", &n, &m);
  g1.init();
  int s, t;
  scanf("%d%d", &s, &t);
  for (int i = 0; i < (m); ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    g1.addedge(x, y, z);
    g1.addedge(y, x, z);
  }
  for (int i = 1; i <= (n); ++i) scanf("%I64d %I64d", &ti[i], &ci[i]);
  g2.init();
  for (int i = 1; i <= (n); ++i) {
    g1.spfa(i);
    for (int j = 1; j <= (n); ++j)
      if (i != j) {
        if (g1.dis[j] <= ti[i]) {
          g2.addedge(i, j, ci[i]);
        }
      }
  }
  g2.spfa(s);
  if (g2.dis[t] == 0x3FFFFFFFFFFFFFFFLL)
    puts("-1");
  else
    printf("%I64d\n", g2.dis[t]);
  return 0;
}
