import std.stdio;
import std.algorithm;
import std.container;
import core.stdc.stdio;
import std.typecons;

int n,k;
int[][] sg;
int[][] graph;

int[2][] queue;
bool[] visited;

int gSize=0;
void buildGraph(int idx,int r){
	visited[] = false;
	int qc=0;
	visited[idx]=true;
	foreach(c;sg[idx]){
		queue[qc++] = [1,c];
		visited[c]=true;
	}
	for(int i=0;i<qc;i++){
		int s=queue[i][0];
		int p=queue[i][1];
		if(s>r)
			return;
		graph[idx] ~= p;
		gSize++;
		foreach(c;sg[p]){
			if(!visited[c]){
				visited[c] = true;
				queue[qc++] = [s+1,c];
			}
		}
	}
}

void main(){
	scanf("%d%d",&n,&k);
	graph = new int[][n];
	sg = new int[][n];
	int[] cs=new int[n];
	int[] rs=new int[n];
	queue = new int[2][n];
	visited = new bool[n];
	for(int i=0;i<n;i++){
		scanf("%d%d",&cs[i],&rs[i]);
	}
	for(int i=0;i<k;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		sg[--a] ~= --b;
		sg[b] ~= a;
	}
	for(int i=0;i<n;i++){
		buildGraph(i,rs[i]);
	}
	visited[] = false;
	alias Tuple!(int,"cost",int,"idx") ci;
	alias BinaryHeap!(ci[]) pq;
	pq q = pq(new ci[gSize+1],0);
	q.insert(ci(0,0));
	int ans;
	while(!q.empty){
		ci s = q.front;
		q.removeFront;
		if(s.idx==n-1){
			ans=s.cost;
			break;
		}
		if(visited[s.idx])
			continue;
		visited[s.idx]=true;
		foreach(c;graph[s.idx]){
			if(!visited[c]){
				q.insert(ci(s.cost+cs[s.idx],c));
			}
		}
	}
	printf("%d\n",ans);
}