#include <bits/stdc++.h>
using namespace std;
struct qqq{
int a=0,s=0,d=0,f;
}s[3010];
queue <int> a;
int q,w,d,f,g,h,l[3010],t[3010],n[3010],cnm=1;
qqq j;
bool k[3010];
int csh(){
for(int e=0;e<3010;e++){
k[e]=1;
}
}
int qq(int z,int x){
n[cnm]=l[z];
t[cnm]=x;
l[z]=cnm++;
}
int main()
{
int c,m;
cin>>q>>w;
for(int e=1;e<=w;e++){
cin>>d>>f;
qq(d,f);
qq(f,d);
}
csh();
a.push(1);
k[1]=0;
while(!a.empty()){
g=a.front();
h=g;
a.pop();
g=l[g];
while(g!=0){
if(k[t[g]]){
k[t[g]]=0;
a.push(t[g]);
s[t[g]].a=s[h].a+1;
}
g=n[g];
}
}
csh();
cin>>g>>c;
a.push(g);
k[g]=0;
while(!a.empty()){
g=a.front();
h=g;
a.pop();
g=l[g];
while(g!=0){
if(k[t[g]]){
k[t[g]]=0;
a.push(t[g]);
s[t[g]].s=s[h].s+1;
}
g=n[g];
}
}
csh();
cin>>g>>m;
a.push(g);
k[g]=0;
while(!a.empty()){
g=a.front();
h=g;
a.pop();
g=l[g];
while(g!=0){
if(k[t[g]]){
k[t[g]]=0;
a.push(t[g]);
s[t[g]].d=s[h].d+1;
}
g=n[g];
}
}
int r=5000;
for(int e=1;e<=q;e++){
if(s[e].a+s[e].s<=c&&s[e].a+s[e].d<=m){
if(s[e].a+s[e].s+s[e].d<r){
r=s[e].a+s[e].s+s[e].d;
}
}
}
cout<<(r==5000?-1:w-r);
}