private Pair findFirstNonzeroColumn(int i, int j){//in column j after i-1
        Pair p=new Pair(-1,j);
        int k=i;
        if (j>=rows){
            p.x=i;
            p.y=-2;
            return p;
        }
        while (elements[k][j]==0){
            if ((k+1)<rows) k++;
            else break;
        }
        if (k<rows) {
            swapRows(i, k);
            p.x=k;
            p.y=j;
            return p;
        }
        return p;
    }