Eliminate Obstacles

medium
You are given an n x m integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step.

Return the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (n - 1, m - 1) given that you can eliminate at most k obstacles. If it is not possible to find such walk return -1.

Input Format

n m n*m integers k

Output Format

minimum number of steps to walk in single line

Constraints

.

Notice

.

Example

Input
5
3
0 0 0
1 1 0
0 0 0
0 1 1
0 0 0 
1
Output
6
Previous
Longest Unbalanced Subsequence
Next
Lets Create Balanced String

Related Questions