#include #include #include #include using namespace std; using P = pair; 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"; }