#000357

O-kljakavac2

Good old Zvonko recently find girlfriend Nikolinu Klipović who like he, has walking problems and must walk like knight in chess.


They are really love to play on biiiiiiiiiiig school playground R x K, made of square panels 1x1. Every panel is determined with row and column and it is big enough to both Zvonko and Nikolina can stand on it simultaneously.


As we know positions of two friends on playground, answer minimal number of pseudo steps Zvonko and Nikolina must made to meet each other. One pseudo step is like L movement of Knight. (two field in one of four directions: up, left, down, right and then one panel left or right.)


NOTICE 1: Every similarity with real characters is accidental.


InputFirst line of input contain six integers R, K, Xz, Yz, Xn i Yn, all separated with empty space. Integers represent: number of rows, number of columns, row coordinate for Zvonko, column coordinate for Zvonko, row coordinate for Nikolina and column coordinate for Nikolina.
All numbers on input are positive and <= 2 000 000 000 and (1 <= Xz,Xn <= K) a (1 <= Yz,Yn <= R).

OutputOn first line of output write one integer: minimal number of steps Nikolina and Zvonko must made to meet each other on any panel on playground. If they can not meet at any panel, write -1.

NOTICE 2:
in 50% test cases both R and R <= 8.
in 80% test cases both K and K <= 1000.


Input:

8 8 2 2 7 7

Output:

4


Input:

10 20 1 2 10 20

Output:

9


In first example, Zvonko and Nikolina will meet earlier after 4 pseudo steps. It can be on any of fields:
2,2 - Zvonko 0 pseudo steps, Nikolina 4,
3,4 - Zvonko 1 pseudo steps, Nikolina 3,
5,3 - Zvonko 2 pseudo steps, Nikolina 2,
6,5 - Zvonko 3 pseudo steps, Nikolina 1,
7,7 - Zvonko 4 pseudo steps, Nikolina 0.

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.