import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Grooves {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int hunters = Integer.parseInt(input[0]);
        int grooves = Integer.parseInt(input[1]);

        HashMap<Long, Integer> hashmap = new HashMap<>();
        int maxY = 0;

        for (int i = 0; i < grooves; i++) {
            String[] line = br.readLine().split(" ");
            int x1 = Integer.parseInt(line[0]);
            int y = Integer.parseInt(line[1]);
            int x2 = Integer.parseInt(line[2]);
            maxY = Math.max(maxY, y);

            long merged1 = (long)x1 << 32 | y; // x1 y1
            long merged2 = (long)x2 << 32 | y; // x2 y2
            hashmap.put(merged1, x2);
            hashmap.put(merged2, x1);
        }

        int[] huntersX = new int[hunters + 1];

        for (int i = 0; i < huntersX.length; i++) {
            huntersX[i] = i;
        }

        for (int i = 1; i <= maxY; i++) {
            long pos = i;

            for (int j = 1; j <= hunters; j++) {
                pos = (pos & 0xFFFFFFFFL) | ((long)huntersX[j] << 32);
                Integer ppos = hashmap.get(pos);

                if (ppos != null) {
                    huntersX[j] = ppos;
                }
            }
        }

        for (int i = 1; i < huntersX.length; i++) {
            System.out.println(huntersX[i]);
        }
    }
}
