package no3679_nannkadekkaimushi; import java.util.*; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); sc.nextInt(); sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); int hf = sc.nextInt(); int wf = sc.nextInt(); int he = sc.nextInt(); int we = sc.nextInt(); int p = sc.nextInt(); int q = sc.nextInt(); int ans = Math.abs(p - x) + Math.abs(q - y); int l = 0; //初期位置が虫の上 if(x <= hf) { //System.out.println("Up"); //左側 if(y <= wf) { l = Math.abs(y - wf) + Math.abs(x - hf); x = hf; y = wf; }//右側 else if(y > we) { l = Math.abs(y - we) + Math.abs(x - hf); x = hf; y = wf; }//真上 else { l = Math.abs(x - hf); x = hf; } }//初期位置が虫と同じくらいの高さ else if(x > hf && x <= he) { //左側 if(y <= wf) { l = Math.abs(wf - y); y = wf; }//右側 else if(y > we) { l = Math.abs(we - y); y = we; }//それ以外は動かない }//初期位置が虫の下 else if(x > he) { //左 if(y <= wf) { l = Math.abs(x - he) + Math.abs(y - wf); x = he; y = wf; }//右 else if(y > we) { l = Math.abs(x - he) + Math.abs(y - we); x = he; y = we; }//真下 else { l = Math.abs(x - he); x = he; } }ans += l + Math.abs(p - x) + Math.abs(q - y); System.out.println(ans); } }