//#include //using namespace atcoder; //using mint = modint; #include #define int long long #define sint signed #define endl "\n" // fflush(stdout); #define ALL(v) (v).begin(),(v).end() #define Vi vector #define VVi vector #define VVVi vector #define Vm vector #define VVm vector #define Vs vector #define Vd vector #define Vc vector #define Pii pair #define Pdd pair #define VPii vector #define Tiii tuple #define VTiii vector #define PQi priority_queue #define PQir priority_queue,greater> #define pb push_back #define mp make_pair #define mt make_tuple #define itos to_string #define stoi stoll #define FI first #define SE second #define cYES cout<<"YES"<()) #define rep(i,a,b) for(int i=a;i=b;i--) #define dem(a,b) ((a+b-1)/(b)) #define INF 3000000000000000000 // 3.0*10^18 #define MAX LLONG_MAX #define PI acos(-1.0L) using namespace std; /* debug */ template ostream& operator<<(ostream& os,const vector &V){int N=V.size(); if(N==0){os<<'.';return os;}rep(i,0,N-1){os< ostream& operator<<(ostream& os,const vector> &V){ int N=V.size();rep(i,0,N-1)os< ostream& operator<<(ostream& os, pair const&P){os<void Vin(vector &v){int n=v.size();rep(i,0,n)cin>>v[i];} int scomb(int n, int r){if(r<0||r>n)return 0;if((n-r)n-r;--i){a=a*i;}for(int i=1;i0){ret+=n%10;n/=10;}return ret;} int digit(int k,int i){string s = itos(k);return s[s.size()-i]-'0';} templatevoid press(T &v){v.erase(unique(ALL(v)),v.end());} int SMALLER(Vi &a,int x){return lower_bound(a.begin(),a.end(),x)-a.begin();} int orSMALLER(Vi &a,int x){return upper_bound(a.begin(),a.end(),x)-a.begin();} int BIGGER(Vi &a,int x){return a.size()-orSMALLER(a,x);} int orBIGGER(Vi &a,int x){return a.size()-SMALLER(a,x);} int COUNT(Vi &a,int x) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} int maxind(Vi &a){return max_element(ALL(a))-a.begin();} int minind(Vi &a){return min_element(ALL(a))-a.begin();} templatebool chmax(T &a,T b) {if(abool chmin(T &a,T b) {if(a>b){a=b;return 1;}return 0;} /* Vi zip(Vi b){int Z=b.size(); Pii p[Z+10];int a=b.size();Vi l(a);for(int i=0;i> n >> m; Vi b(n),c(n); VPii d(n); rep(i,0,n) { cin >> b[i] >> c[i]; b[i]--,c[i]--; d[i] = mp(c[i],b[i]); } sort(ALL(d)); d.pb(mp(INF,INF)); int ans = 0; Vi t; rep(i,0,n) { t.pb(d[i].SE); if(d[i].FI!=d[i+1].FI) { int ct = 0,maxx = 0; t.pb(INF); rep(j,0,t.size()-1) { if(t[j]==t[j+1]) { ct++; } else { ct++; chmax(maxx,ct); ct = 0; } } ans += t.size()-maxx-1; t = {}; } } cout << ans << endl; } signed main() { init(); int q = 1; //cin >> q; while(q--) sol(); return 0; }