i came across this logic after reading question.

suppose we have n**n matrix ,for calculating the answer for worst case scenario suppose chef first open box which is placed on middle of matrix(n/2,n/2),now this box would tell us which sub-matrix we will choose in order to reach the final box(whether right-up,right-down,left-up,left-down),now we would have have sub-matrix of only 1/4th sizeof original,again choose middle of this sub-matrix and open the box which is placed on it, it will again break matrix into 4 parts ,and this would go on till we reach at the end of matrixâ€¦ at the end you would find the final box . Simply this recursive solution would take LOG(N) steps,now formalize this into m**n matrix,and find max of m and n,and answer would be as simply as it is LOG(max(M,N));