#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
int n, m, x, y;
int t[1005], c[1005];
int vis[1005];
long long dis[1005], minc[1005];
vector<pair<int, int> > adj[1005], cost[1005];
void SPFA1(int st) {
  for (int i = 1; i <= n; i++) {
    dis[i] = inf;
    vis[i] = false;
  }
  vis[st] = true;
  dis[st] = 0;
  queue<int> Q;
  Q.push(st);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    vis[u] = false;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].first;
      if (dis[u] + (long long)adj[u][i].second < dis[v]) {
        dis[v] = dis[u] + (long long)adj[u][i].second;
        if (!vis[v]) {
          vis[v] = true;
          Q.push(v);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (i != st && dis[i] <= t[st]) {
      cost[st].push_back(make_pair(i, c[st]));
    }
}
void SPFA2(int st) {
  for (int i = 1; i <= n; i++) {
    minc[i] = inf;
    vis[i] = false;
  }
  vis[st] = true;
  minc[st] = 0;
  queue<int> Q;
  Q.push(st);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    vis[u] = false;
    for (int i = 0; i < cost[u].size(); i++) {
      int v = cost[u][i].first;
      if (minc[u] + (long long)cost[u][i].second < minc[v]) {
        minc[v] = minc[u] + (long long)cost[u][i].second;
        if (!vis[v]) {
          vis[v] = true;
          Q.push(v);
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &x, &y);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    adj[a].push_back(make_pair(b, c));
    adj[b].push_back(make_pair(a, c));
  }
  for (int i = 1; i <= n; i++) scanf("%d%d", &t[i], &c[i]);
  for (int i = 1; i <= n; i++) SPFA1(i);
  SPFA2(x);
  if (minc[y] == inf) minc[y] = -1LL;
  cout << minc[y] << endl;
  return 0;
}
