#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int R, C; cin >> R >> C;
    int sy, sx; cin >> sy >> sx; sy--; sx--;
    int gy, gx; cin >> gy >> gx; gy--; gx--;
    cout << abs(sy - gy) + abs(sx - gx) << "\n";
}