How to get top-most group ID

How do I get a top level group ID? I have a group thats nested a few layers down, when I access the ParentGroupId, it just returns one level up. Whats the best way to get the "root" group, or the most top group?

Parents Reply Children