#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a,b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<P; const int MAX_N = 100005; class UF { private: int sz; public: vector kind; //所属しているグループ番号 vector > inc; //グループのメンバー UF(int node_size){ sz = node_size; kind.resize(sz),inc.resize(sz); rep(i,sz){ kind[i] = i; inc[i].pb(i); } } bool same(int a,int b){ return kind[a] == kind[b]; } void unite(int a,int b) { if(same(a,b)) return; if(inc[kind[a]].size() < inc[kind[b]].size() || (inc[kind[a]].size() == inc[kind[b]].size() && kind[a] > kind[b])){ swap(a,b); } int ga = kind[a],gb = kind[b]; rep(i,inc[gb].size()) kind[inc[gb][i]] = ga; inc[ga].insert(inc[ga].end(),inc[gb].begin(),inc[gb].end()); inc[gb].clear(); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n,m; cin >> n >> m; UF uf(n); rep(i,m){ int a,b; cin >> a >> b; uf.unite(a-1,b-1); } rep(i,n){ cout << uf.kind[i]+1 << endl; } return 0; }