#include <bits/stdc++.h>
using namespace std;
const int nmax = 1010;
vector<pair<int, int> > v[nmax];
vector<pair<int, int> > g[nmax];
int c[nmax];
int t[nmax];
long long d[nmax];
int id[nmax];
int n;
set<pair<int, int> > s;
void construct(int start) {
  memset(id, 63, n * sizeof(int));
  s.insert(make_pair(0, start));
  id[start] = 0;
  int x;
  set<pair<int, int> >::iterator it;
  while (!s.empty()) {
    it = s.begin();
    x = it->second;
    s.erase(it);
    for (int i = 0; i < (int)v[x].size(); ++i) {
      if (id[v[x][i].first] > id[x] + v[x][i].second) {
        it = s.find(make_pair(id[v[x][i].first], v[x][i].first));
        if (it != s.end()) {
          s.erase(it);
        }
        id[v[x][i].first] = id[x] + v[x][i].second;
        s.insert(make_pair(id[v[x][i].first], v[x][i].first));
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (id[i] <= t[start]) {
      g[start].push_back(make_pair(i, c[start]));
    }
  }
}
long long getAns(int start, int end) {
  for (int i = 0; i < nmax; ++i) {
    d[i] = 1LL << 60;
  }
  long long inf = 1LL << 60;
  s.insert(make_pair(0, start));
  d[start] = 0;
  int x;
  set<pair<int, int> >::iterator it;
  while (!s.empty()) {
    it = s.begin();
    x = it->second;
    s.erase(it);
    for (int i = 0; i < (int)g[x].size(); ++i) {
      if (d[g[x][i].first] > d[x] + g[x][i].second) {
        it = s.find(make_pair(d[g[x][i].first], g[x][i].first));
        if (it != s.end()) {
          s.erase(it);
        }
        d[g[x][i].first] = d[x] + g[x][i].second;
        s.insert(make_pair(d[g[x][i].first], g[x][i].first));
      }
    }
  }
  return d[end] == inf ? -1 : d[end];
}
int main() {
  int m;
  int S, E;
  int x, y, w;
  scanf("%d%d", &n, &m);
  scanf("%d%d", &S, &E);
  --S;
  --E;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &x, &y, &w);
    --x;
    --y;
    v[x].push_back(make_pair(y, w));
    v[y].push_back(make_pair(x, w));
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &t[i], &c[i]);
  }
  for (int i = 0; i < n; ++i) {
    construct(i);
  }
  cout << getAns(S, E) << endl;
  return 0;
}
