class Solution {
public:
    vector<int> findElement(vector<vector<int> > mat, int n, int m, int x) {
        if(n==0 && m==0)    return {};

        int i=0, j=m-1;
        while(i<n && j>=0) {
            if(mat[i][j] == x) {
                return {i, j};
            } else if(mat[i][j] < x) {
                i++;
            } else if(mat[i][j] > x) {
                j--;
            }
        }         
        return {};
    }
};