#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

class Edge{
public:
    int from, to, rev;
    Int cost, lim;
    Edge(int from, int to, Int cost, int lim = -1, Int rev = -1):
        from(from),to(to),cost(cost),lim(lim),rev(rev){}
};


class Graph{
public:
    int n;
    int m;
    vector<vector<Edge>> edge;
    Graph(int n = 0):n(n),m(0){
        edge = vector<vector<Edge>>(n);
    }
    void add_edge(int from, int to, int cost = 1, int lim = -1)
        {
            if(lim == -1){
                edge[from].push_back(Edge(from, to, cost));
                return;
            }
            edge[from].push_back(Edge(from, to, cost, lim, edge[to].size()));
            edge[to].push_back(Edge(to, from, -cost, 0, edge[from].size() - 1));
        }
};



class Dinic{
public:
    Graph *g;
    vector<int> iter, level, come;

    Dinic(){};
    void bfs(int s){
        queue<int> q;
        fill(level.begin(), level.end(), INF);
        level[s] = 0;
        q.push(s);
        while(!q.empty()){
            int x = q.front();q.pop();
            for(auto e:g->edge[x]){
                if(level[e.to] != INF)continue;
                if(e.lim <= 0)continue;
                level[e.to] = level[x] + 1;
                q.push(e.to);
            }
        }
    }

    Int dfs(int s, int t, Int f){
        if(s == t)return f;
        if(come[s])return 0;
        come[s] = true;
        for(int &i = iter[s];i < g->edge[s].size();i++){
            Edge &e = g->edge[s][i];
            if(e.lim <= 0)continue;
            Int tmp = dfs(e.to, t, min(f, e.lim));
            if(tmp == 0)continue;
            e.lim -= tmp;
            g->edge[e.to][e.rev].lim += tmp;
            return tmp;
        }
        return 0;
    }
    Int max_flow(Graph &_g, int s, int t){
        g = &_g;
        iter = vector<int>(g->n);
        level = vector<int>(g->n);
        come = vector<int>(g->n, 0);
        Int res = 0;
        while(true){
            bfs(s);
            if(level[t] == INF)break;
            fill(iter.begin(), iter.end(), 0);
            while(true){
                fill(come.begin(), come.end(), false);
                Int tmp = dfs(s, t, INF);
                if(tmp == 0)break;
                else res += tmp;
            }
        }
        return res;   
    }  
};

Int n, m,u, v;
Int S, T, U, V;
int main(){
    cin >> n >> m;
    cin >> S >> T >> U >> V;
    Graph g1(n + 3), g2(n+3);
    int X = n+1, Y = n + 2;
    for(int i = 0;i < m;i++){
        cin >> u >> v;
        g1.add_edge(u, v, 1, 1);
        g1.add_edge(v, u, 1, 1);
        g2.add_edge(u, v, 1, 1);
        g2.add_edge(v, u, 1, 1);
    }
    g1.add_edge(X, S, 1, 1100000);
    g1.add_edge(X, U, 1, 1100000);
    g1.add_edge(T, Y, 1, 1100000);
    g1.add_edge(V, Y, 1, 1100000);
    g2.add_edge(X, S, 1, 1100000);
    g2.add_edge(X, V, 1, 1100000);
    g2.add_edge(T, Y, 1, 1100000);
    g2.add_edge(U, Y, 1, 1100000);
    Dinic d;
    Int ans = LINF;
    if(S != V && T != U)ans = min(ans, d.max_flow(g1, X, Y));
    if(S != U && T != V)ans = min(ans, d.max_flow(g2, X, Y));
    cout << ans << endl;
    
    
    return 0;
}



Measured memory_bytes: 43568