def pad_to_match(num, matches, max_len=3):
    """
    z-fills a number until a match has been found.
    :param num: the number to zfill
    :param matches: the available matches
    :param max_len: the maximum length to zfill
    :return: the z-filled number if a match was found otherwise the original value
    """
    padded_num = '{}'.format(num)
    while len(padded_num) < max_len and padded_num not in matches:
        padded_num = padded_num.zfill(len(padded_num) + 1)
        if padded_num in matches:
            return padded_num
    return '{}'.format(num)