def add_to_existing_groups(no_people, existing_groups, max_size):
    """
        Attempts to add the given number of people to the list of
        existing groups without exceeding the maximum group size.

        Modifies the list of existing groups. Returns the number of people
        remaining after the attempt.

        attempt_to_add_to_existing_groups(int, list(Group), int) -> int
    """
    for group in existing_groups:
        if no_people == 0:
            break

        # We want to add as many people to the group as possible
        max_that_can_be_added = max_size - group.get_size()
        amount_that_can_be_added = min(no_people, max_that_can_be_added)
        group.alter_size(amount_that_can_be_added)
        no_people -= amount_that_can_be_added
    
    return no_people