const int maxn=4e6+7,mod=1e9+7;
ll h[maxn],idx;
struct node{
int e,ne;
ll w;
}edge[maxn];
void add(int u,int v,ll w){
edge[idx]={v,h[u],w};h[u]=idx++;
}
int n,m,sx,sy,fx,fy,x[maxn],y[maxn],vx[maxn],vy[maxn];
ll dis[maxn];
bool st[maxn];
int get_x_id(int t){
return lower_bound(vx+1,vx+1+m,t)-vx;
}
int get_y_id(int t){
return lower_bound(vy+1,vy+1+m,t)-vy;
}
ll dijkstra(int s){
memset(dis,0x3f,sizeof dis);
dis[s]=0;
///建立一个维护最小值的优先队列
priority_queue<PLL,vector<PLL>,greater<PLL>>heap;
heap.push({s,0ll});///起始点放入队列
while(heap.size()){
auto t=heap.top();///最小值
heap.pop();
ll ver=t.second,d=t.first;
if(st[ver]) continue;///该点更新
st[ver]=true;
for(int i=h[ver];i!=-1;i=edge[i].ne){
int j=edge[i].e;
if(dis[j]>d+edge[i].w){
dis[j]=d+edge[i].w;
heap.push({dis[j],j});
}
}
}
return dis[3*m+1];
}
int main(){
memset(h,-1,sizeof h);
n=read,m=read;
sx=read,sy=read,fx=read,fy=read;
rep(i,1,m){
x[i]=read,y[i]=read;
vx[i]=x[i];vy[i]=y[i];
}
sort(vx+1,vx+1+m);sort(vy+1,vy+1+m);
rep(i,1,m){//起点向跳跃点
add(0,i+m,abs(sx-vx[i]));
add(0,i+2*m,abs(sy-vy[i]));
}
//vx.erase(unique(vx.begin(),vx.end()),vx.end());
// vy.erase(unique(vy.begin(),vy.end()),vy.end());
rep(i,1,m){
add(i,3*m+1,abs(fx-x[i])+abs(fy-y[i]));//2 终点向跳跃点
int xid=get_x_id(x[i])+m;
add(i,xid,0);add(xid,i,0);//5 跳跃点到x轴
int yid=get_y_id(y[i])+2*m;
add(i,yid,0);add(yid,i,0);//6跳跃点到y轴
// add(0,xid,abs(sx-x[i]));add(0,yid,abs(sy-y[i]));//1
}
add(0,3*m+1,abs(sx-fx)+abs(sy-fy));//起点向终点
for(int i=2;i<=m;i++)//x轴之间
add(i+m,i+m-1,abs(vx[i]-vx[i-1])),add(i+m-1,i+m,abs(vx[i]-vx[i-1]));
for(int i=2;i<=m;i++)//y轴之间
add(i+2*m,i+2*m-1,abs(vy[i]-vy[i-1])),add(i+2*m-1,i+2*m,abs(vy[i]-vy[i-1]));
dijkstra(0);
write(dis[3*m+1]);
return 0;
}