#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n;
    int a,b;
    int c,d;
    scanf("%d %d",&m,&n);
    scanf("%d %d",&a,&b);
    scanf("%d %d",&c,&d);
    printf("%d",min(abs(c-a),m-abs(c-a))+min(abs(d-b),n-abs(d-b)));
    return 0;
}