def find_nearest(sorted_list, x):
    if x <= sorted_list[0]:
        return sorted_list[0]
    elif x >= sorted_list[-1]:
        return sorted_list[-1]
    else:
        lower = find_le(sorted_list, x)
        upper = find_ge(sorted_list, x)
        if (x - lower) > (upper - x):
            return upper
        else:
            return lower