import java.util.Scanner;

public class Vorpspejs {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int dx = in.nextInt();
		int dy = in.nextInt();
		
		int ax = in.nextInt();
		int ay = in.nextInt();
		
		int bx = in.nextInt();
		int by = in.nextInt();
		
		in.close();
		
		
		int lx = Math.abs(ax - bx);
		int ly = Math.abs(ay - by);
		
		int l = Math.min(lx, dx - lx) + Math.min(ly, dy - ly);
		
		
		System.out.println(l);
	}
}
