import java.util.*;

public class groove2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Stack<Integer>[] stacks = new Stack[N + 1];
        for (int i = 1; i <= N; i++) {
            stacks[i] = new Stack<>();
            stacks[i].push(i);
        }
        sc.nextLine();
        List<int []> listik = new ArrayList<>();

        for (int i = 0; i < M; i++) {
            listik.add(new int []{sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt()});
            sc.nextLine();

        }
        listik.sort(Comparator.comparingInt(a->a[3]));

        for (int [] riadok : listik) {
            int a = riadok[0];
            int b = riadok[2];
            for (int j = 1; j <=N ; j++) {
                if (stacks[j].peek() == a) {
                    stacks[j].push(b);
                } else if (stacks[j].peek() == b) {
                    stacks[j].push(a);
                }
            }

        }
        for (int i = 1; i <= N; i++) {
            System.out.println(stacks[i].peek());

        }
    }
}
