#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;#define f first
#define s second
llN,K;vector<pair<int,int>>swaps;vector<int>jumpTable;vector<int>myGroup;vector<vector<int>>groups;vector<vector<int>>trace;vector<int>ans;// STEP 1: simulate to get the trace for each nodevoidsimulation(vector<ll>&a){// include itselffor(inti=1;i<=N;i++){trace[i].push_back(i);}// simulate first K cyclesfor(inti=0;i<swaps.size();i++){intl=swaps[i].f;intr=swaps[i].s;trace[a[l]].push_back(r);trace[a[r]].push_back(i);swap(a[l],a[r]);}}// STEP 2: create jump tablevoidmake_table(vector<ll>&a){// create jumpTablefor(inti=1;i<a.size();i++){jumpTable[a[i]]=i;}}// STEP 3: find groups of cows using DFSvoidfindCycles(vector<ll>&a){intcurrentID=0;for(inti=1;i<=N;i++){if(myGroup[i]!=-1){continue;}vector<int>groupIds;myGroup[i]=currentID;groupIds.push_back(i);intj=jumpTable[i];intcurrPhase=0;while(j!=i){currPhase++;myGroup[j]=currentID;groupIds.push_back(j);j=jumpTable[j];}groups.push_back(groupIds);currentID++;}}intmain(){cin>>N>>K;swaps.resize(K);trace.resize(N+1);jumpTable.resize(N+1);myGroup.resize(N+1,-1);ans.resize(N+1,0);for(inti=0;i<K;i++){inta,b;cin>>a>>b;swaps[i].f=a;swaps[i].s=b;}vector<ll>a(N+1);iota(a.begin(),a.end(),0);simulation(a);make_table(a);findCycles(a);map<int,int>finAns;for(intgroupId=0;groupId<groups.size();groupId++){// everythingunordered_set<int>currSet;for(intj=0;j<groups[groupId].size();j++){// mergefor(autok:trace[groups[groupId][j]]){currSet.insert(k);}}finAns[groupId]=currSet.size();continue;}for(inti=1;i<=N;i++){cout<<max(finAns[myGroup[i]],1)<<endl;}}