#include <iostream>
#include <fstream>
#include <queue>
#include <memory.h>
using namespace std;
const int MAXN = 180;
const int MAXM = MAXN * MAXN;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
ifstream fin("alee.in");
ofstream fout("alee.out");
int a[MAXN][MAXN];
int n, m, x, y, xf, yf, xs, ys;
queue <pair <int, int> > q;
void citire(){
fin >> n;
fin >> m;
memset(a, -1, sizeof(a));
for (int i=1; i<=m; i++){
fin >> x >> y;
a[x][y]= -2;
}
fin >> xs >> ys >> xf >> yf;
a[xs][ys]= 1;
}
inline bool inside(int x, int y, int n){
return 1<=x && x <=n && 1<=y && y<=n;
}
void solve(){
q.push(make_pair(xs,ys));
while(!q.empty()){
pair<int, int> pos = q.front();
q.pop();
for(int d = 0; d < 4; d++){
int newx= pos.first + dx[d];
int newy= pos.second +dy[d];
if(inside(newx, newy, n) && a[newx][newy]==-1){
q.push(make_pair(newx,newy));
a[newx][newy]=a[pos.first][pos.second]+1;
}
}
}
}
void write(){
fout << a[xf][yf];
}
int main(){citire();
solve();
write();
}