#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
template<typename T>class Dinic{
private:
    int V;
    vector<int> level, iter;
    void bfs(int s){
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[s] = 0;
        que.push(s);
        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(auto & e: G[v]){
                if(e.cap > 0 and level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
    T dfs(int v, int t, T f){
        if(v == t) {
            return f;
        }
        for(int& i = iter[v]; i < (int) G[v].size(); i++){
            edge&e = G[v][i];
            if(e.cap > 0 and level[v] < level[e.to]){
                T d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    
public:
    struct edge{
        int to;
        T cap;
        int rev;
    };
    vector<vector<edge> > G;
    
    Dinic(int node_size) : V(node_size), level(V), iter(V), G(V){}
    void add_edge(int from,int to,T cap) {
        G[from].push_back((edge){to,cap,(int)G[to].size()});
        G[to].push_back((edge){from,(T)0,(int)G[from].size()-1});
    }
    T solve(int s, int t){
        T flow = 0;
        for(;;){
            bfs(s);
            if(level[t] < 0)return flow;
            fill(iter.begin(), iter.end(),0);
            T f;
            while((f = dfs(s,t,numeric_limits<T>::max()))>0){
                flow += f;
            }
        }
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, S, T, U, V;
    cin >> N >> M >> S >> T >> U >> V;
    S--,T--,U--,V--;
    vector<vector<int>> G(N);
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int temp1, temp2;
    //(S,U),(T,V)
    {
        Dinic<int> dinic(N + 2);
        int super1 = N, super2 = N + 1;
        for(int i = 0; i < N; i++){
            for(int x : G[i]){
                dinic.add_edge(i, x, 1);
            }
        }
        dinic.add_edge(super1, S, 1000000);
        dinic.add_edge(super1, U, 1000000);
        dinic.add_edge(T, super2, 1000000);
        dinic.add_edge(V, super2, 1000000);
        temp1 =dinic.solve(super1, super2);
        show(temp1);
    }
    //(S,V),(U,T)
    {
        Dinic<int> dinic(N + 2);
        int super1 = N, super2 = N + 1;
        for(int i = 0; i < N; i++){
            for(int x : G[i]){
                dinic.add_edge(i, x, 1);
            }
        }
        dinic.add_edge(super1, S, 1000000);
        dinic.add_edge(super1, V, 1000000);
        dinic.add_edge(T, super2, 1000000);
        dinic.add_edge(U, super2, 1000000);
        temp2 =dinic.solve(super1, super2);
        show(temp2);
    }
    cout << min(temp1, temp2) << endl;
}


Measured memory_bytes: 17620