class Solution {

public:

int kthSmallest(vector<vector<int>>& matrix, int k) {

int n = matrix.size();

vector<int> tmp = matrix[0];

if (n > 1)

{

for (int i = 1; i < n; i++)

{

tmp.insert(tmp.end(), matrix[i].begin(), matrix[i].end());

}

}

std::sort(tmp.begin(), tmp.end());

return tmp.at(k - 1);

}

};