#include <bits/stdc++.h>
using namespace std;
const int N = 1009;
const int INF = 0x3f3f3f3f;
struct LT {
  int to, nex, dis;
} L[N << 1];
int F[N], cnt = 1;
void add(int f, int t, int d) {
  L[cnt].to = t;
  L[cnt].nex = F[f];
  L[cnt].dis = d;
  F[f] = cnt++;
}
int val[N];
int dis[N];
long long dp[N];
int inque[N], inS[N];
int n, m;
int st, en;
queue<int> que, S;
int redis[N];
void spfa() {
  memset(dp, INF, sizeof(dp));
  dp[st] = 0;
  S.push(st);
  while (!S.empty()) {
    int tmp = S.front();
    S.pop();
    inS[tmp] = 0;
    que.push(tmp);
    memset(redis, 0, sizeof(redis));
    redis[tmp] = dis[tmp];
    while (!que.empty()) {
      int e = que.front();
      que.pop();
      inque[e] = 0;
      for (int i = F[e]; i; i = L[i].nex) {
        int to = L[i].to, d = L[i].dis;
        if (redis[to] + d <= redis[e]) {
          redis[to] = redis[e] - d;
          if (!inque[to]) que.push(to), inque[to] = 1;
          if (dp[to] > dp[tmp] + val[tmp]) {
            dp[to] = dp[tmp] + val[tmp];
            if (!inS[to]) {
              S.push(to), inS[to] = 1;
            }
          }
        }
      }
    }
  }
  if (dp[0] == dp[en])
    cout << "-1" << endl;
  else
    cout << dp[en] << endl;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &st, &en);
  int a, b, c;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    add(a, b, c);
    add(b, a, c);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &dis[i], &val[i]);
  }
  spfa();
  return 0;
}
