Issue with the Sequence number of series

Like when I delete a bad invoice, the series doesn’t update the right sequence; it continues the sequence numbers as the bad invoice is not deleted. It seems like it keeps the deleted numbers in a cache.

Like I have an invoice number 050, which is wrong. When I delete it and create the new one, the new one starts using the next number, “051”. If I delete the “051”, the new one will start using “052.” but I need to create a correct invoice as a replacement number “050”, not the next one.

Any help would be much appreciated.
Thanks

You need to go and update the naming series ,the current value will be the last valid sequence as per screenshot below