Please tell me how is it wrong,

I tried submitting the solution for this ROBOTS AND PATH,my doubt is how come my code doesnt passes all the test cases when i change the order of if statement inside the for loop for creating my dp,as you can see when i first take the top element not equal to -1 its passes all the test cases but if i first check for left not equal to -1 it show incorrect answers,?Please clear my doubt on this since i could just upload one i uploaded the wrong one if you just change the order of if statements it gives you the right answers for all test cases

You are getting wrong answer due to another reason not this. Check ur condition of dp[r][c]==-1 and dp[1][1]==-1 you should first print 0 then terminate the program.

thank you so much sir ill always appreciate it ,im marking it as resolved