#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9, MAXN = (int)1e3;
const long long ooll = 1000000000000000000ll;
int weight[MAXN][MAXN], length[MAXN][MAXN], ride[MAXN], cost[MAXN], n, m, first,
    last;
vector<vector<int> > graph;
int temp[MAXN];
void calculate(int v) {
  memset(temp, 0, sizeof temp);
  set<pair<int, int> > s;
  s.insert(make_pair(0, v));
  temp[v] = -1;
  while (!s.empty()) {
    int r = s.begin()->first;
    int u = s.begin()->second;
    weight[v][u] = cost[v];
    for (int i = 0; i < (graph[u].size()); i++) {
      int node = graph[u][i];
      if (r + length[u][node] <= ride[v]) {
        if (!temp[node]) {
          temp[node] = r + length[u][node];
          s.insert(make_pair(temp[node], node));
        } else if (temp[node] > r + length[u][node]) {
          s.erase(s.find(make_pair(temp[node], node)));
          temp[node] = r + length[u][node];
          s.insert(make_pair(temp[node], node));
        }
      }
    }
    s.erase(make_pair(r, u));
  }
  weight[v][v] = 0;
}
long long ans[MAXN];
void dijkstra() {
  set<pair<long long, int> > s;
  for (int i = 0; i < (n); i++) ans[i] = ooll, s.insert(make_pair(ooll, i));
  ans[first] = 0;
  s.erase(make_pair(ooll, first));
  s.insert(make_pair(0, first));
  while (!s.empty()) {
    long long r = s.begin()->first;
    if (r == ooll) break;
    int u = s.begin()->second;
    for (int i = 0; i < (graph[u].size()); i++) {
      int node = graph[u][i];
      if (ans[node] > r + weight[u][node]) {
        s.erase(s.find(make_pair(ans[node], node)));
        ans[node] = r + weight[u][node];
        s.insert(make_pair(ans[node], node));
      }
    }
    s.erase(make_pair(r, u));
  }
}
int main() {
  cin >> n >> m >> first >> last;
  first--, last--;
  graph = vector<vector<int> >(n);
  int x, y, z;
  for (int i = 0; i < (m); i++) {
    cin >> x >> y >> z;
    x--, y--;
    if (!length[x][y])
      graph[x].push_back(y), graph[y].push_back(x),
          length[x][y] = length[y][x] = z;
    else
      length[x][y] = length[y][x] = min(length[x][y], z);
  }
  for (int i = 0; i < (n); i++) cin >> ride[i] >> cost[i];
  for (int i = 0; i < (n); i++) calculate(i);
  graph = vector<vector<int> >(n);
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++)
      if (weight[i][j]) graph[i].push_back(j);
  dijkstra();
  if (ans[last] == ooll)
    cout << "-1" << endl;
  else
    cout << ans[last] << endl;
  return 0;
}
