#include <bits/stdc++.h>
using namespace std;
int N, E;
int source_node, sink_node;
vector<vector<pair<long long, long long> > > path;
vector<pair<long long, long long> > taxi;
long long cost[1010][1010];
long long final_cost[1010];
inline void print() {
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      cout << cost[i][j] << "\t";
    }
    cout << "\n";
  }
}
inline void read() {
  scanf("%d %d", &N, &E);
  scanf("%d %d", &source_node, &sink_node);
  path.assign(N + 5, vector<pair<long long, long long> >());
  for (int i = 0; i < E; ++i) {
    long long source, sink, weight;
    scanf("%I64d %I64d %I64d", &source, &sink, &weight);
    path[source].push_back(make_pair(sink, weight));
    path[sink].push_back(make_pair(source, weight));
  }
  taxi.assign(N + 5, make_pair(0, 0));
  for (int i = 0; i < N; ++i) {
    long long source = i + 1, meter, money;
    scanf("%I64d %I64d", &meter, &money);
    taxi[source] = make_pair(meter, money);
  }
}
inline void bfs1(long long now_node) {
  for (int i = 0; i < N + 5; ++i) {
    cost[now_node][i] = -1;
  }
  queue<long long> q;
  q.push(now_node);
  cost[now_node][now_node] = 0;
  while (q.empty() == false) {
    long long source = q.front();
    q.pop();
    for (int i = 0; i < (int)(path[source]).size(); ++i) {
      long long sink = path[source][i].first;
      long long weight = cost[now_node][source] + path[source][i].second;
      if (cost[now_node][sink] == -1) {
        q.push(sink);
        cost[now_node][sink] = weight;
      } else if (weight < cost[now_node][sink]) {
        q.push(sink);
        cost[now_node][sink] = weight;
      }
    }
  }
}
inline void bfs2(int now_node) {
  memset(final_cost, -1, sizeof(final_cost));
  queue<long long> q;
  q.push(now_node);
  final_cost[now_node] = 0;
  while (q.empty() == false) {
    long long source = q.front();
    q.pop();
    for (int sink = 1; sink <= N; ++sink) {
      if (source != sink && cost[source][sink] != -1 &&
          cost[source][sink] <= taxi[source].first) {
        if (final_cost[sink] == -1) {
          q.push(sink);
          final_cost[sink] = final_cost[source] + taxi[source].second;
        } else if (final_cost[source] + taxi[source].second <
                   final_cost[sink]) {
          q.push(sink);
          final_cost[sink] = final_cost[source] + taxi[source].second;
        }
      }
    }
  }
  printf("%I64d\n", final_cost[sink_node]);
}
inline void proc() {
  for (int i = 1; i <= N; ++i) {
    bfs1(i);
  }
  bfs2(source_node);
}
int main() {
  read();
  proc();
  return 0;
}
