#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
long long dis[maxn][maxn], cost[maxn];
vector<pair<int, long long> > edge1[maxn], edge2[maxn];
set<pair<long long, int> > st;
void dij(int source) {
  while (st.size()) {
    int u = (*st.begin()).second;
    st.erase(st.begin());
    for (int i = 0; i < edge1[u].size(); i++) {
      int v = edge1[u][i].first;
      long long w = edge1[u][i].second;
      if (dis[source][v] > dis[source][u] + w) {
        st.erase(make_pair(dis[source][v], v));
        dis[source][v] = dis[source][u] + w;
        st.insert(make_pair(dis[source][v], v));
      }
    }
  }
}
void dij1() {
  while (st.size()) {
    int u = (*st.begin()).second;
    st.erase(st.begin());
    for (int i = 0; i < edge2[u].size(); i++) {
      int v = edge2[u][i].first;
      long long w = edge2[u][i].second;
      if (cost[v] > cost[u] + w) {
        st.erase(make_pair(cost[v], v));
        cost[v] = cost[u] + w;
        st.insert(make_pair(cost[v], v));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int x, y;
  cin >> x >> y;
  x--;
  y--;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    edge1[u].push_back(make_pair(v, w));
    edge1[v].push_back(make_pair(u, w));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) dis[i][j] = inf;
    dis[i][i] = 0;
    st.insert(make_pair(0, i));
    dij(i);
  }
  for (int i = 0; i < n; i++) {
    int max_dis, cost;
    cin >> max_dis >> cost;
    for (int j = 0; j < n; j++)
      if (dis[i][j] <= (long long)max_dis)
        edge2[i].push_back(make_pair(j, cost));
  }
  for (int i = 0; i < n; i++) cost[i] = inf;
  cost[x] = 0;
  st.insert(make_pair(0, x));
  dij1();
  if (cost[y] == inf)
    cout << -1;
  else
    cout << cost[y];
  return 0;
}
