import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); for(int i=1;i=0 && possibley[r]=0) { //mark the possible step with step number if(coveredspots[possiblex[r]][possibley[r]]==-1){ coveredspots[possiblex[r]][possibley[r]]=p+1; anyMovementRecorded=true; } } } //return if n-1,n-1 is covered in this movement if(coveredspots[n-1][n-1]!=-1) { return coveredspots[n-1][n-1]; } } } } if(anyMovementRecorded==false) { //no movement recorded, return with -1 return -1; } } return -1; } }