import java.util.Scanner;

public class groove {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] pole = new int[2][N+1];
        int[][] pole2 = new int[4][M];
        int max = 0;
        sc.nextLine();
        for (int i = 0; i < M; i++) {
            pole2[0][i] = sc.nextInt();
            pole2[1][i] = sc.nextInt();
            pole2[2][i] = sc.nextInt();
            pole2[3][i] = sc.nextInt();
            if (pole2[1][i] > max) {
                max = pole2[1][i];
            }
            sc.nextLine();
        }
        for (int i = 1; i <= N ; i++) {
            pole[0][i] = i;
        }
        for (int i = 1; i <= max; i++) {
            for (int j = 1; j <= N; j++) {
                pole[1][j] = pole[1][j] + 1;
                for (int k = 0; k < M; k++) {
                    if(pole[0][j] == pole2[0][k] && pole[1][j] == pole2[1][k]) {
                        pole[0][j] = pole2[2][k];
                    }
                    else if(pole[0][j] == pole2[2][k] && pole[1][j] == pole2[3][k]) {
                        pole[0][j] = pole2[0][k];
                    }
                }
            }
        }
        for (int i = 1; i <= N; i++) {
            System.out.println(pole[0][i]);
        }
    }
}
