using System; using System.Collections.Generic; using System.Linq; class Solution { static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = vals[0]; var m = vals[1]; var battles = new int[m][]; for (int i = 0; i < m; i++) { battles[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } var team = Enumerable.Range(0, n + 1).ToArray(); foreach (var battle in battles) { var boss = battle.Select(i => team[i]).ToArray(); var win = boss[0]; var lose = boss[1]; if (win == lose) { continue; } var counts = Enumerable.Range(0, 2).Select(i => team.Count(t => t == boss[i])).ToArray(); if (counts[0] < counts[1]) { win = boss[1]; lose = boss[0]; } else if (counts[0] == counts[1] && boss[0] > boss[1]) { win = boss[1]; lose = boss[0]; } for (int i = 1; i <= n; i++) { if (team[i] == lose) { team[i] = win; } } } foreach (var t in team.Skip(1)) { Console.WriteLine(t); } } }