import java.math.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int column = sc.nextInt(); int row = sc.nextInt(); int[][] maze = new int[row][column]; int[][] ho = new int[row][column]; int[] vx = {0,1,0,-1}; int[] vy={-1,0,1,0}; for(int i=0;i quex = new LinkedList(); Queue quey = new LinkedList(); Queue moto = new LinkedList(); Queue hoo = new LinkedList(); quex.offer(1); quey.offer(0); quex.offer(0); quey.offer(1); hoo.offer(1); hoo.offer(1); moto.offer(maze[0][0]); moto.offer(maze[0][0]); while(!quex.isEmpty()){ int nx = quex.poll(); int ny = quey.poll(); int nowho = hoo.poll(); if(nx == column && ny == row){ System.out.println(ho[nx][ny]); return; } int moto1 = moto.poll(); for(int i=0;i<4;i++){ int nex = nx+vx[i]; int ney = ny+vy[i]; if(nex<0 || nex > column-1 || ney<0 || ney > row-1) continue; if( ((moto1 > maze[ny][nx] && maze[ney][nex]>maze[ny][nx]) || (moto1 < maze[ny][nx] && maze[ney][nex]