Exit from the labyrinth#4820

Exit from the labyrinth

1 second
64 megabytes
Easy

During a tornado in a European region, many trees were knocked down. A few days later, a boy named Ilya went for a walk and discovered that the fallen trees had created a labyrinth. Delighted, Ilya began to explore and play within it. Suddenly, his teacher called to ask why Ilya had not been seen for so long. To avoid getting in trouble for leaving the camp area without permission, Ilya wanted to return home quickly, but he also wanted to enjoy wandering through the labyrinth.

Help him determine the fastest way to reach his house.

Input

The first line contains two positive integers and (1 \leq N, M \leq 1000). The following lines each contain characters, describing the labyrinth. Movable positions are denoted by the character "0", and positions blocked by fallen trees by the character "1". After the labyrinth description, there are four integers: x_1, y_1, x_2, y_2—the coordinates (column and row numbers) of Ilya's starting position and his house (1 \leq x_1, x_2 \leq M, 1 \leq y_1, y_2 \leq N).

Output

Output a single number: the length of the shortest path from (x_1, y_1) to (x_2, y_2). If Ilya cannot reach the house, output "-1".

Examples

Example 1

Loading
Loading