#include <bits/stdc++.h>
using namespace std;
template <typename T>
int size(T& a) {
  return (int)a.size();
}
template <typename T>
T sqr(T a) {
  return a * a;
}
long long max_dist[2000];
long long cost[2000];
int n, m, s, t;
long long tdist[2000];
long long dist[2000];
set<pair<long long, int> > Q;
bool used[2000];
int head[2000];
int to[100000];
int nxt[100000];
long long weight[100000];
int edge;
struct Entry {
  long long dist;
  int to;
};
Entry adj[2000][2000];
void ae(int i, int j, long long w) {
  nxt[edge] = head[i];
  to[edge] = j;
  weight[edge] = w;
  head[i] = edge++;
}
void add_edge(int i, int j, long long w) {
  ae(i, j, w);
  ae(j, i, w);
}
void dij(int v) {
  for (int i = (0); i < (n); ++i) tdist[i] = 1000000000000000LL;
  Q.clear();
  tdist[v] = 0LL;
  memset((used), (0), sizeof(used));
  Q.insert(make_pair(0LL, v));
  while (size(Q)) {
    pair<long long, int> p = *Q.begin();
    Q.erase(Q.begin());
    int u = p.second;
    used[u] = 1;
    long long d = p.first;
    for (int e = head[u]; e >= 0; e = nxt[e]) {
      if (used[to[e]]) continue;
      if (tdist[to[e]] > d + weight[e]) {
        Q.erase(make_pair(tdist[to[e]], to[e]));
        tdist[to[e]] = d + weight[e];
        Q.insert(make_pair(tdist[to[e]], to[e]));
      }
    }
  }
  for (int i = (0); i < (n); ++i) {
    if (i == v)
      adj[v][v].dist = 1000000000000000LL;
    else {
      adj[v][i].dist = tdist[i];
      adj[v][i].to = i;
    }
  }
}
int cmp(struct Entry a, struct Entry b) {
  if (a.dist < b.dist) return 1;
  if (a.dist > b.dist) return 0;
  return a.to < b.to ? 1 : 0;
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d %d", &s, &t);
  s--, t--;
  memset((head), (-1), sizeof(head));
  edge = 0;
  for (int i = (0); i < (m); ++i) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    u--, v--;
    add_edge(u, v, w);
  }
  for (int i = (0); i < (n); ++i) {
    dij(i);
  }
  for (int i = (0); i < (n); ++i) {
    cin >> max_dist[i] >> cost[i];
  }
  for (int i = (0); i < (n); ++i) {
    dist[i] = 1000000000000000LL;
  }
  dist[s] = 0;
  memset((used), (0), sizeof(used));
  for (int i = (0); i < (n); ++i) {
    int arg_min = -1;
    for (int j = (0); j < (n); ++j) {
      if (used[j]) continue;
      if (arg_min == -1 || dist[j] < dist[arg_min]) arg_min = j;
    }
    if (arg_min == t) break;
    if (arg_min == -1) break;
    used[arg_min] = 1;
    for (int j = (0); j < (n); ++j) {
      if (adj[arg_min][j].dist > max_dist[arg_min]) continue;
      if (used[adj[arg_min][j].to]) continue;
      dist[adj[arg_min][j].to] =
          min(dist[adj[arg_min][j].to], dist[arg_min] + cost[arg_min]);
    }
  }
  if (dist[t] == 1000000000000000LL)
    puts("-1");
  else
    cout << dist[t];
}
