public class Solution {

public int kthSmallest(int[][] matrix, int k) {

```
PriorityQueue<Integer> pq= new PriorityQueue(k, Collections.reverseOrder());
for(int i=0;i<matrix.length;i++){
for(int j=0;j<matrix[0].length;j++){
if(pq.size()<k)
pq.add(matrix[i][j]);
else{
int temp=pq.peek();
if(temp>matrix[i][j]){
pq.poll();
pq.offer(matrix[i][j]);
}
}
}
}
return pq.poll();
}
```

}