import hashlib
import itertools


def md5_with_prefix(input, prefix, start_with=0):
    """Determine first number that generates a hash with the given prefix."""
    md5_input = hashlib.md5(input)

    for number in itertools.count(start_with):
        md5 = md5_input.copy()
        md5.update(str(number).encode('ascii'))
        if md5.hexdigest().startswith(prefix):
            return number