#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000;
const int inf1 = 1000000001;
vector<pair<int, int> > g[1010];
pair<int, int> v[1010];
long long cost[1010];
bool done[1010];
int n;
set<pair<int, int> > S;
int dist[1010];
void relax(int nr, int d, int v) {
  for (int i = 0; i < (n); ++i) {
    dist[i] = (i == nr ? 0 : inf1);
    S.insert(make_pair(dist[i], i));
  }
  while (!S.empty()) {
    pair<int, int> akt = *S.begin();
    S.erase(akt);
    if (akt.first > d) break;
    if (cost[akt.second] > cost[nr] + v) cost[akt.second] = cost[nr] + v;
    for (int i = 0; i < ((int)g[akt.second].size()); ++i)
      if (dist[g[akt.second][i].first] >
          dist[akt.second] + g[akt.second][i].second) {
        pair<int, int> pom =
            make_pair(dist[g[akt.second][i].first], g[akt.second][i].first);
        S.erase(pom);
        dist[g[akt.second][i].first] =
            dist[akt.second] + g[akt.second][i].second;
        S.insert(
            make_pair(dist[g[akt.second][i].first], g[akt.second][i].first));
      }
  }
  S.clear();
}
int main() {
  int m, x, y;
  scanf("%d%d%d%d", &n, &m, &x, &y);
  x--;
  y--;
  for (int i = 0; i < (m); ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  for (int i = 0; i < (n); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[i] = make_pair(a, b);
  }
  for (int i = 0; i < (n); ++i) cost[i] = inf;
  cost[x] = 0;
  int akt = x;
  for (int i = 0; i < (n); ++i) {
    if (akt == y) {
      printf("%lld\n", cost[y]);
      return 0;
    }
    relax(akt, v[akt].first, v[akt].second);
    done[akt] = 1;
    long long minv = inf;
    int wsk = -1;
    for (int j = 0; j < (n); ++j)
      if (!done[j] && cost[j] < minv) {
        minv = cost[j];
        wsk = j;
      }
    if (wsk == -1) break;
    akt = wsk;
  }
  printf("-1\n");
  return 0;
}
