def replace_u_end_month(month):
    """Find the latest legitimate month."""
    month = month.lstrip('-')
    if month == 'uu' or month == '1u':
        return '12'
    if month == 'u0':
        return '10'
    if month == '0u':
        return '09'
    if month[1] in ['1', '2']:
        # 'u1' or 'u2'
        return month.replace('u', '1')
    # Otherwise it should match r'u[3-9]'.
    return month.replace('u', '0')