def find_first_month_and_year(num_months, end_month, end_year):
    """Find the month and year that is num_months prior to end_month, end_year.
    Num_months includes the end_month and the first_month."""

    excess = num_months - end_month
    full_years_prior = excess / 12
    months_in_partial_years_prior = excess % 12
    if months_in_partial_years_prior > 0:
        first_year = end_year - full_years_prior - 1
        first_month = 13 - months_in_partial_years_prior
    else:
        first_year = end_year - full_years_prior
        first_month = 1
    return first_month, first_year