Is there any function that returns the top level category ID by passing its child or grand child ID?

For example category ID 1 is a root level category, it has a sub category 5 and 5 has a sub category 9. If I pass 9 or 5 to a function it should return 1 i.e. the root / top level category.

Thanks and Regards