from pathlib import Path


def process(file: Path) -> int:
    """
    Process input file yielding the submission value

    :param file: file containing the input values
    :return: value to submit
    """

    lines = (l for l in open(file))
    timestamp = int(next(lines))
    bus_id_list = [int(bus_id) for bus_id in next(lines).strip().split(',')
                   if bus_id.isdecimal()]

    time = timestamp
    while not any(time % bus_id == 0 for bus_id in bus_id_list):
        time += 1
    earliest_bus = next(bus_id for bus_id in bus_id_list if time % bus_id == 0)

    submission = (time - timestamp) * earliest_bus
    return submission