#include <bits/stdc++.h>
using namespace std;
template <class T>
void inline checkMin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
void inline checkMax(T &a, T b) {
  if (a < b) a = b;
}
int head[1010];
int cnt;
long long len[1010], cost[1010];
struct Edg {
  int v, next;
  long long w;
} edg[1010 * 1010];
void add(int a, int b, long long c) {
  edg[cnt].v = b;
  edg[cnt].w = c;
  edg[cnt].next = head[a];
  head[a] = cnt++;
}
bool inque[1010];
void spfa(int s, long long dis[], int n) {
  for (int i = 1; i <= n; ++i) dis[i] = -1LL;
  dis[s] = 0LL;
  queue<int> q;
  q.push(s);
  memset(inque, 0, sizeof(inque));
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inque[u] = false;
    for (int i = head[u]; i != -1; i = edg[i].next) {
      int v = edg[i].v;
      if (dis[v] == -1 || dis[v] > dis[u] + edg[i].w) {
        dis[v] = dis[u] + edg[i].w;
        if (!inque[v]) q.push(v);
        inque[v] = true;
      }
    }
  }
}
long long dis[1010][1010];
int main() {
  int n, m, s, t, a, b, c;
  while (scanf("%d%d", &n, &m) != EOF) {
    scanf("%d%d", &s, &t);
    memset(head, -1, sizeof(head));
    cnt = 0;
    for (int i = 0; i < m; ++i) {
      scanf("%d%d%d", &a, &b, &c);
      add(a, b, (long long)c);
      add(b, a, (long long)c);
    }
    for (int i = 1; i <= n; ++i) scanf("%I64d%I64d", &len[i], &cost[i]);
    for (int i = 1; i <= n; ++i) spfa(i, dis[i], n);
    memset(head, -1, sizeof(head));
    cnt = 0;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        if (i != j && dis[i][j] <= len[i] && dis[i][j] != -1)
          add(i, j, cost[i]);
    spfa(s, dis[s], n);
    printf("%I64d\n", dis[s][t]);
  }
  return 0;
}
