Find the next "smallest" int value

Hello community,

I want to set an default value for an attribute.
Imagine, you have an int attribute.
Like 1, 2, 4, 5, 8

and when you add a user, he shall get the “next” value, in this case, it shall be “3”.

Do you have an idea, how I could implement this? Because for that, I need to get all informations of my table and find out the smallest available one?

Thanks a lot