Function to find lowest unoccupied depth

Ugh, I’m sorry for asking because I KNOW I’ve seen this function here before!!! I’ve tried so many searches though but I guess I don’t know exactly what to ask… So if anyone can help me I need a function to find the lowest available depth for use in attach movies and such. And I also wanted to ask if running a function like this a lot would be too intensive to be practical. Thanks if anyone can help.