import calendar


def get_year_for_first_weekday(weekday=0):
    """Get the year that starts on 'weekday', eg. Monday=0."""

    if weekday > 6:
        raise ValueError("weekday must be between 0 and 6")
    year = 2020
    not_found = True
    while not_found:
        firstday = calendar.weekday(year, 1, 1)
        if firstday == weekday and not calendar.isleap(year):
            not_found = False
        else:
            year = year - 1
    return year