import sys def paixu(key,array):
    result=[]
    aaa=[]
    changdu=0  n=len(array) for i in range(n):
        changdu+=len(array[i]) while len(aaa)<changdu: for j in range(n): if len(array[j])<key:
                result.append(array[j][0:]) del array[j][0:] else:
                result.append(array[j][0:key]) del array[j][0:key]
            aaa=[] for i in result:
                aaa.extend(i)
    RRR=[] for i in result:
        RRR.extend(i) return RRR if __name__ == "__main__":
    key = int(input())
    array = [] while 1: try:
            array.append(list(map(int, input().split(',')))) except: break   #print(paixu(key, array))  A=paixu(key,array)
    A = ','.join(('%s' %i for i in A)) print(A)