#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MAX = 5100;
int n, k;
int a, b;
int cost[MAX], lim[MAX];

const int INF = 1<<29;
vint graph[MAX];
bool can[MAX][MAX];
int dp[MAX];

int main() {
    while (cin >> n >> k) {
        for (int i = 0; i < n; ++i) cin >> cost[i] >> lim[i];
        for (int i = 0; i < MAX; ++i) graph[i].clear();
        for (int i = 0; i < k; ++i) {
            cin >> a >> b; --a; --b;
            graph[a].PB(b); graph[b].PB(a);
        }
        
        for (int i = 0; i < n; ++i) {
            vint ver;
            
            int dist[MAX];
            memset(dist, -1, sizeof(dist));
            dist[i] = 0;
            queue<int> que;
            que.push(i);
            
            while (!que.empty()) {
                int v = que.front(); que.pop();
                ver.PB(v);
                
                if (dist[v] == lim[i]) continue;
                for (int j = 0; j < graph[v].size(); ++j) {
                    int to = graph[v][j];
                    if (dist[to] == -1) {
                        dist[to] = dist[v] + 1;
                        que.push(to);
                    }
                }
            }
            
            for (int j = 0; j < ver.size(); ++j) can[i][ver[j]] = true;
        }
            
        for (int i = 0; i < MAX; ++i) dp[i] = INF;
        dp[0] = 0;
            
        bool used[MAX];
        memset(used, 0, sizeof(used));
        while (true) {
            int v = -1, Min = INF;
            for (int i = 0; i < n; ++i) {
                if (used[i]) continue;
                if (chmin(Min, dp[i])) v = i;
            }
            if (v == -1) break;
            used[v] = true;
            for (int i = 0; i < n; ++i) {
                if (can[v][i]) chmin(dp[i], dp[v] + cost[v]);
            }
        }
         
        cout << dp[n-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 26608