public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n,k;
        while ((n=scanner.nextInt())>0){
            k=scanner.nextInt();
            List<Point> list=new ArrayList<>(n*n);
            for(int i=0;i<n;++i){
                for(int j=0;j<n;++j){
                    list.add(new Point(i,j,scanner.nextInt()));
                }
            }
            Collections.sort(list);
            System.out.println(entrance1(list,k,n));
        }
        scanner.nextInt();//读取最后一个输入
    }