I agree with the rest of everyone where it is a very bad idea to implement your own find minimal open number. But at where I work, we are given a closed set of number and when a number is free up, we must reuse.
Here is how we did it.
We do not delete the row, but set all values of every column null, So what you do is
SELECT min(id) WHERE columnA IS NULL, and if this returns something, we reuse, otherwise, insert a new row.