#include using namespace std; #define FOR(i, n) for(int i = 0; i < (n); i++) #define MEM(a, x) memset(a, x, sizeof(a)) #define ALL(a) a.begin(), a.end() #define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) typedef long long ll; typedef pair P; int par[10005], ran[10005], sum[10005], bos[10005]; int n, m; void init(int n) { FOR(i, n) { par[i] = i; bos[i] = i; ran[i] = 0; sum[i] = 1; } } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } // x lose, y win void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; sum[y] = sum[x] = sum[x] + sum[y]; bos[x] = bos[y]; if (ran[x] < ran[y]) { par[x] = y; } else { par[y] = x; if (ran[x] == ran[y]) ran[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin >> n >> m; init(n); FOR(i, m) { int a, b; cin >> a >> b; a--; b--; if (!same(a, b)) { int _a = find(a), _b = find(b); if (sum[_a] == sum[_b]) { if (bos[_a] > bos[_b]) unite(a, b); else unite(b, a); } if (sum[_a] < sum[_b]) unite(a, b); else if (sum[_a] > sum[_b]) unite(b, a); } } FOR(i, n) cout << bos[find(i)]+1 << endl; return 0; }