#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
vector<pair<int, long long> > e[MAXN];
int pre[MAXN];
bool visit[MAXN];
long long dis[MAXN];
int t[MAXN], c[MAXN];
int n, m;
vector<pair<int, long long> > e2[MAXN];
int x, y;
void makegraph(int s) {
  memset(visit, false, sizeof(visit));
  priority_queue<pair<long long, int> > q;
  q.push(make_pair(0, s));
  for (int i = 0; i < n; i++) dis[i] = 1e15;
  dis[s] = 0;
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (dis[u] > t[s]) return;
    if (visit[u]) continue;
    e2[s].push_back(make_pair(u, c[s]));
    visit[u] = true;
    for (int i = 0; i < e[u].size(); i++) {
      int v = e[u][i].first;
      long long w = e[u][i].second;
      if (dis[u] + w < dis[v]) {
        dis[v] = dis[u] + w;
        pre[v] = u;
        q.push(make_pair(-dis[v], v));
      }
    }
  }
  return;
}
void dijkstra() {
  memset(visit, false, sizeof(visit));
  priority_queue<pair<long long, int> > q;
  q.push(make_pair(0, x));
  for (int i = 0; i < n; i++) dis[i] = 1e15;
  dis[x] = 0;
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (u == y) {
      cout << dis[y] << endl;
      return;
    }
    if (visit[u]) continue;
    visit[u] = true;
    for (int i = 0; i < e2[u].size(); i++) {
      int v = e2[u][i].first;
      long long w = e2[u][i].second;
      if (dis[u] + w < dis[v]) {
        dis[v] = dis[u] + w;
        q.push(make_pair(-dis[v], v));
      }
    }
  }
  cout << "-1" << endl;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &x, &y);
  x--;
  y--;
  for (int i = 0; i < m; i++) {
    int u, v;
    long long w;
    scanf("%d%d%I64d", &u, &v, &w);
    u--;
    v--;
    e[u].push_back(make_pair(v, w));
    e[v].push_back(make_pair(u, w));
  }
  for (int i = 0; i < n; i++) scanf("%d%d", &t[i], &c[i]);
  for (int i = 0; i < n; i++) makegraph(i);
  dijkstra();
  return 0;
}
