#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#define dbg_line(x) cout << (x) << '\n'
#define dbg(x) cout << x << " "
#define len(x) (int)x.length()

using namespace std;

// <--> Report constants <-->

typedef pair<int, int> pii;
const int max_n = 1e5 + 5;
const ll inf = 1e9;
const ll m_inf = -1e9;
const ll mod = 1e9 + 7;
const int base = 32;

// <--> Report variables <-->

int n, m, p, q, s, t;
bool adj[1005][1005];
set<pair<int, int>> visited;
int dx[4] = {-1, -1, 1, 1};
int dy[4] = {-1, 1, -1, 1};

// <--> Main Code is Here <-->

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void call_file() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

struct Distance{
    int x, y;
    int d;
};

bool check(int i, int j){
    return i >=1 && i <= n && j >= 1 && j <= n && !adj[i][j];
}

int BFS(){
    queue<Distance> Q;
    visited.insert({p, q});
    Q.push({p, q, 0});
    while (!Q.empty()){
        Distance u = Q.front();
        Q.pop();
        for (int i = 0; i < 4; i++){
            int x = u.x, y = u.y;
            while (check(x + dx[i], y + dy[i])){
                x += dx[i];
                y += dy[i];
                if (x == s && y == t){
                    return u.d + 1;
                }
                if (visited.find({x, y}) == visited.end()){
                    visited.insert({x, y});
                    Q.push({x, y, u.d + 1});
                }
            }
        }
    }
    return -1;
}

int main() {
    setIO();
    call_file();
    cin >> n >> m >> p >> q >> s >> t;
    while (m--){
        int x, y;
        cin >> x >> y;
        adj[x][y] = true;
    }
    cout << BFS();
    
}
