#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
const int Mod = 1e9 + 7;
const int N = 2;
struct Edge {
  long long to, w, next;
} edge[maxn * maxn];
int edge_num;
int head[maxn];
long long d[maxn][maxn];
void Init() {
  memset(head, -1, sizeof head);
  edge_num = 0;
}
void add_edge(int x, int y, int z) {
  edge[edge_num] = (Edge){y, z, head[x]};
  head[x] = edge_num++;
  edge[edge_num] = (Edge){x, z, head[y]};
  head[y] = edge_num++;
}
long long C[maxn], T[maxn];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
void dijkstra(int s) {
  while (!q.empty()) q.pop();
  memset(d[s], 0x3f3f3f3f3f3f3f3f, sizeof d[s]);
  q.push(pair<long long, long long>(d[s][s] = 0, s));
  while (!q.empty()) {
    long long u = q.top().second, t = q.top().first;
    q.pop();
    if (t > d[s][u]) continue;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      long long v = edge[i].to, w = edge[i].w;
      if (d[s][v] > d[s][u] + w)
        q.push(pair<long long, long long>(d[s][v] = d[s][u] + w, v));
    }
  }
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    Init();
    int s, t;
    scanf("%d%d", &s, &t);
    for (int i = 1; i <= m; i++) {
      long long x, y, z;
      scanf("%I64d%I64d%I64d", &x, &y, &z);
      add_edge(x, y, z);
    }
    for (int i = 1; i <= n; i++) dijkstra(i);
    for (int i = 1; i <= n; i++) scanf("%I64d%I64d", &T[i], &C[i]);
    edge_num = 0;
    memset(head, -1, sizeof head);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i != j && d[i][j] <= T[i]) {
          edge[edge_num] = (Edge){j, C[i], head[i]};
          head[i] = edge_num++;
        }
      }
    }
    dijkstra(s);
    if (d[s][t] == 0x3f3f3f3f3f3f3f3f)
      puts("-1");
    else
      printf("%I64d\n", d[s][t]);
  }
  return 0;
}
