public long removeMax() {
        long max = -1;
        for (int i = 0; i < nElems; i++)
            if (a[i] > max)
                max = a[i];

        if (max != -1)
            delete(max);
        return max;
    }