			
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

#define rep(i,st,ed) for (int i=st;i<=ed;++i)

typedef long long LL;
const LL INF=1e18;
const int N=200005;

std:: vector <int> E[N],G[N];

LL a[N],b[N],f[N],g[N];
int fa[N],rk[N];

bool vis[N];

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

void dfs(int x) {
	if (G[x].empty()) {
		f[x]=a[x]+b[x],g[x]=b[x];
		return ;
	}
	g[x]=b[x],f[x]=INF;
	for (int y:G[x]) dfs(y),g[x]+=g[y];
	for (int y:G[x]) {
		f[x]=std:: min(f[x],std:: max(f[y],a[x])+g[x]-g[y]);
	}
}

int find(int x) {
	return !fa[x]?x:(fa[x]=find(fa[x]));
}

bool cmp(int x,int y) {
	return a[x]<a[y];
}

int main(void) {
	int n=read(),m=read();
	rep(i,1,n) {
		a[i]=read(),b[i]=read();
		a[i]=std:: max(a[i]-b[i],0LL);
		rk[i]=i;
	}
	rep(i,1,m) {
		int x=read(),y=read();
		E[x].push_back(y);
		E[y].push_back(x);
	}
	std:: sort(rk+1,rk+n+1,cmp);
	rep(ti,1,n) {
		int x=rk[ti]; vis[x]=1;
		for (int y:E[x]) {
			if (!vis[y]) continue;
			if (find(y)==find(x)) continue;
			G[x].push_back(find(y));
			fa[find(y)]=find(x);
		}
	}
	rep(i,1,n) if (find(i)==i) {
		dfs(i),printf("%lld\n", f[i]);
	}
	return 0;
}