class Hunter:
    def __init__(self,x,y):
        self.x = x
        self.y = y

class Groove:
    def __init__(self,start_x,start_y, end_x, end_y):
        self.start_x = start_x
        self.start_y = start_y
        self.end_x = end_x
        self.end_y = end_y

def main():
    line = input()
    line = line.split(" ")
    hunter_count = int(line[0])
    grooves_count = int(line[1])
    grooves = [[] for _ in range(grooves_count)]
    max_y = 0
    hunters = []

    for i in range(grooves_count):
        line = input()
        line = line.split(" ")
        groove = Groove(int(line[0]), int(line[1]), int(line[2]), int(line[3]))
        grooves[groove.start_y - 1].append(groove)
        if groove.end_y > max_y:
            max_y = groove.end_y

        if 0 < i < hunter_count + 1:
            hunters.append(Hunter(i, 0))

    if len(hunters) < hunter_count:
        for i in range(len(hunters), hunter_count):
            hunters.append(Hunter(i + 1, 0))

    for i in range(1, max_y + 1):
        if i - 1 < grooves_count:
            break
        for groove in grooves[i - 1]:
            for hunter in hunters:
                hunter.y = i
                if hunter.x == groove.start_x:
                    hunter.x = groove.end_x

                elif hunter.x == groove.end_x:
                    hunter.x = groove.start_x



    for hunter in hunters:
        print(hunter.x)










if __name__ == '__main__':
    main()