#include <bits/stdc++.h>
using namespace std;
const int mod = 10;
const int N = 1010;
const long long INF = 1e18;
typedef pair<long long, int> par;
int n, m, x, y;
int cnt, cnt2, head[N], head2[N];
long long d[N][N], D[N];
struct edge {
  int end;
  long long len;
  int next;
} e[N * 2], e2[N * N];
void add_edge(int u, int v, int w) {
  e[cnt].end = v;
  e[cnt].len = w;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
void Add_edge(int u, int v, int w) {
  e2[cnt2].end = v;
  e2[cnt2].len = w;
  e2[cnt2].next = head2[u];
  head2[u] = cnt2++;
}
void dijstra(int k) {
  for (int i = 1; i <= n; i++) {
    d[k][i] = INF;
  }
  d[k][k] = 0;
  priority_queue<pair<long long, int> > q;
  q.push(make_pair(0, k));
  while (!q.empty()) {
    par cur;
    cur = q.top();
    q.pop();
    long long a = -cur.first;
    int b = cur.second;
    for (int i = head[b]; i != -1; i = e[i].next) {
      int en = e[i].end;
      long long len = a + e[i].len;
      if (d[k][en] > len) {
        d[k][en] = len;
        q.push(make_pair(-len, en));
      }
    }
  }
}
void Dijstra(int k) {
  for (int i = 1; i <= n; i++) {
    D[i] = INF;
  }
  D[k] = 0;
  priority_queue<pair<long long, int> > q;
  q.push(make_pair(0, k));
  while (!q.empty()) {
    par cur;
    cur = q.top();
    q.pop();
    long long a = -cur.first;
    int b = cur.second;
    for (int i = head2[b]; i != -1; i = e2[i].next) {
      int en = e2[i].end;
      long long len = a + e2[i].len;
      if (D[en] > len) {
        D[en] = len;
        q.push(make_pair(-len, en));
      }
    }
  }
}
int main() {
  int a, b, c;
  while (~scanf("%d%d", &n, &m)) {
    memset(head, -1, sizeof(head));
    memset(head2, -1, sizeof(head2));
    cnt = cnt2 = 0;
    scanf("%d%d", &x, &y);
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d", &a, &b, &c);
      add_edge(a, b, c);
      add_edge(b, a, c);
    }
    for (int i = 1; i <= n; i++) {
      dijstra(i);
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &a, &b);
      for (int j = 1; j <= n; j++) {
        if (d[i][j] <= a && i != j) {
          Add_edge(i, j, b);
        }
      }
    }
    Dijstra(x);
    if (D[y] == INF)
      printf("-1\n");
    else
      printf("%lld\n", D[y]);
  }
  return 0;
}
