#include <iostream>
#include <cmath>

using namespace std;
int main(){
    int r,c,sy,sx,gy,gx;
    cin >> r >> c >> sy >> sx >> gy >> gx;
    cout << abs(sy - gy) + abs(sx - gx) << endl;

}