#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void checkMin(T& a, T b) {
  if (a > b) a = b;
}
template <typename T>
inline void checkMax(T& a, T b) {
  if (a < b) a = b;
}
const int MAXN = 1005;
const long long INF = ~0ULL >> 2;
int N, M, S, T, t[MAXN], c[MAXN];
vector<pair<int, int> > E[MAXN];
vector<int> e[MAXN];
struct HeapNode {
  int id;
  long long val;
  HeapNode(int a, long long b) : id(a), val(b) {}
  bool operator<(const HeapNode& rhs) const { return val > rhs.val; }
};
void gao(int s, long long t) {
  static bool vis[MAXN];
  fill(vis + 1, vis + N + 1, false);
  static priority_queue<HeapNode> q;
  q.push(HeapNode(s, 0));
  while (!q.empty()) {
    int id = q.top().id;
    long long dis = q.top().val;
    q.pop();
    if (vis[id]) {
      continue;
    }
    vis[id] = true;
    e[s].push_back(id);
    for (__typeof((E[id]).begin()) iter = (E[id]).begin();
         iter != (E[id]).end(); ++iter) {
      int v = iter->first, w = iter->second;
      if (!vis[v] && dis + w <= t) {
        q.push(HeapNode(v, dis + w));
      }
    }
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> N >> M >> S >> T;
  for (int i = 0; i < int(M); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    E[u].push_back(make_pair(v, w));
    E[v].push_back(make_pair(u, w));
  }
  for (int i = 0; i < int(N); ++i) {
    cin >> t[i + 1] >> c[i + 1];
    gao(i + 1, t[i + 1]);
  }
  static bool vis[MAXN];
  static priority_queue<HeapNode> q;
  q.push(HeapNode(S, 0));
  while (!q.empty()) {
    int id = q.top().id;
    long long dis = q.top().val;
    q.pop();
    if (vis[id]) {
      continue;
    }
    vis[id] = true;
    if (id == T) {
      cout << dis << "\n";
      return 0;
    }
    for (__typeof((e[id]).begin()) iter = (e[id]).begin();
         iter != (e[id]).end(); ++iter) {
      int v = *iter;
      if (!vis[v]) {
        q.push(HeapNode(v, dis + c[id]));
      }
    }
  }
  cout << "-1\n";
  return 0;
}
