public int[] longestSequence(int[][] b) {
		Map<Integer, int[]> idmap=new HashMap<>();
		int m=b.length;
		int n=b[0].length;
		for (int i=0; i<m;++i) 
			for (int j=0;j<n;++j) 
				idmap.put(b[i][j], new int[]{i,j});
		boolean[][] v=new boolean[m][n];
		boolean[][] f=new boolean[m][n];
		int[] max=new int[2];
		for (int c=1;c<=m*n;++c) {
			int[] id=idmap.get(c);
			if (!v[id[0]][id[1]]) 
				dfs(b, id[0], id[1], 1, max, v);
			if (!f[id[0]][id[1]])
				bfs(b, id[0], id[1], max, f);
		}
		return max;
	}