def solve(steps):
    """Return value next to 2017.

    :steps: number of steps before every insertion
    :returns: value next to 2017

    >>> solve(3)
    638
    >>> solve(301)
    1642
    """
    buffer = [0]
    c = 0

    for i in range(1, 2018):
        c = (c + steps) % i
        buffer.insert(c + 1, i)
        c += 1

    return buffer[c+1 % 2017]