#include<bits/stdc++.h>
#define endl '\n'
const int inf = 0x3f3f3f3f;
using namespace std;
const int maxn=3e3+1;
int n,m,s1,s2,t1,t2,ans=-1;
queue<int>q;
struct node {
int d1=inf,d2=inf,d3=inf;
vector<int>e;
} v[maxn];
void read() {
cin>>n>>m;
for(int i=1,x,y; i<=m; i++) {
cin>>x>>y;
v[x].e.emplace_back(y),v[y].e.emplace_back(x);
}
cin>>s1>>t1>>s2>>t2;
}
void bfs1(int x){
q.push(x);
v[x].d1=0;
while(q.size()){
int p=q.front();
q.pop();
for(auto i:v[p].e){
if(v[i].d1==inf){
q.push(i);
v[i].d1=v[p].d1+1;
}
}
}
}
void bfs2(int x){
q.push(x);
v[x].d2=0;
while(q.size()){
int p=q.front();
q.pop();
for(auto i:v[p].e){
if(v[i].d2==inf){
q.push(i);
v[i].d2=v[p].d2+1;
}
}
}
}
void bfs3(int x){
q.push(x);
v[x].d3=0;
while(q.size()){
int p=q.front();
q.pop();
for(auto i:v[p].e){
if(v[i].d3==inf){
q.push(i);
v[i].d3=v[p].d3+1;
}
}
}
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
read();
bfs1(1);
if(s1==s2){
cout<<(v[s1].d1>t1||v[s2].d1>t2)?-1:m-v[s1].d1;
return 0;
}
bfs2(s1),bfs3(s2);
for(int i=1;i<=n;i++){
if(v[i].d1+v[i].d2<=t1&&v[i].d1+v[i].d3<=t2){
ans=max(ans,m-v[i].d1-v[i].d2-v[i].d3);
}
}
cout<<ans;
return 0;
}