#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
int M=-100000;

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

int n,k;
cin>>n>>k;

pair<int,int> a[n];pair<int,int> b[n];
fr(i,0,n)b[i]={0,i};
map<int,vi> m;
fr(i,0,n)
{
  cin>>a[i].first>>a[i].second;
  fr(j,a[i].first,a[i].second+1)
  m[j].pb(i);
}
int tot=0;
fr(i,1,201)
{
  if(m.count(i) && m[i].size()>k)
  {
    tot++;
    fr(j,0,sz(m[i]))
    b[m[i][j]].first++;

  }
}

map<int,set<int> > m1;
fr(i,1,201)
{
  if(m.count(i))
  {
    for(auto x:m[i])m1[i].insert(x);
  }
}

//for(auto x:m1)cout<<sz(x.second)<<" ";cout<<endl;

sort(b,b+n);reverse(b,b+n);

vi v;
fr(i,0,n)
{  v.pb(b[i].second);

   for(auto &x:m1)
   {  //cout<<sz(x.second)<<endl;
     if(sz(x.second)>k && x.second.count(b[i].second))
     {x.second.erase(b[i].second);
     if(sz(x.second)==k)tot--;}
   }
   //for(auto x:m1)cout<<sz(x.second)<<" ";cout<<endl;
  if(tot==0)break;

}
cout<<sz(v)<<endl;
for(auto x:v)cout<<x+1<<" ";

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (int)a.size()
#define endl "\n"

#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;};

const ll M=998244353;
const int P=31;
const int MaxM=1001;

int a[200001];

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
int n,k;
cin>>n>>k;
map<int,vector<pii> > m;
vector<pii> v;
  int mx=0;
fr(i,0,n)
{
  int x,y;
  cin>>x>>y;
  v.pb({x,1});
  v.pb({y+1,-1});
  m[x].pb({y,i});
  mx=max(mx,y);
}
srt(v);
  int bal=0;
  memset(a,-1,sizeof a);
   fr(i,0,sz(v))
   {
       if(v[i].S==1)
       {
         bal++;
         a[v[i].F]=bal;
       }
       else {bal--;a[v[i].F]=bal;}
   }
  if(a[1]==-1)a[1]=0;a[mx+1]=0;
  fr(i,2,200001)
  {
    if(a[i]==-1)
    {
      a[i]=a[i-1];
    }
  }
  priority_queue<pii> p;
  ordered_mset s;
ll num=0;vi ans;
  fr(i,1,200001)
  {
    for(auto x:m[i])
    {
      p.push(x);
    }
     int lb=s.order_of_key({i,0});
     int how=a[i]-k-(sz(s)-lb);
     how=max(how,0);
       while(how--)
       {
        s.insert({p.top().F,num++});
         ans.pb(p.top().S+1);
        p.pop();
       }
  }
    cout<<sz(ans)<<endl;
    print(ans)

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
int M=-100000;

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

int n,k;
cin>>n>>k;

pair<int,int> a[n];pair<int,int> b[n];
fr(i,0,n)b[i]={0,i};
map<int,vi> m;
fr(i,0,n)
{
  cin>>a[i].first>>a[i].second;
  fr(j,a[i].first,a[i].second+1)
  m[j].pb(i);
}
int tot=0;
fr(i,1,201)
{
  if(m.count(i) && m[i].size()>k)
  {
    tot+=sz(m[i])-k;
    fr(j,0,sz(m[i]))
    b[m[i][j]].first++;

  }
}

vi v;
sort(b,b+n);reverse(b,b+n);
//for(auto x:b)cout<<x.first<<" "<<x.second<<endl;

int i=0;
while(tot>0)
{
   v.pb(b[i].second);tot-=b[i].first;i++;
}
cout<<sz(v)<<endl;
for(auto x:v)cout<<x+1<<" ";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
int M=-100000;

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

int n,k;
cin>>n>>k;

pair<int,int> a[n];pair<int,int> b[n];
fr(i,0,n)b[i]={0,i};
map<int,vi> m;
fr(i,0,n)
{
  cin>>a[i].first>>a[i].second;
  fr(j,a[i].first,a[i].second+1)
  m[j].pb(i);
}
int tot=0;
fr(i,1,201)
{
  if(m.count(i) && m[i].size()>k)
  {
    tot++;
    fr(j,0,sz(m[i]))
    b[m[i][j]].first++;

  }
}

map<int,set<int> > m1;
fr(i,1,201)
{
  if(m.count(i))
  {
    for(auto &x:m[i])m1[i].insert(x);
  }
}

//for(auto x:m1)cout<<sz(x.second)<<" ";cout<<endl;

sort(b,b+n);reverse(b,b+n);

vi v;
fr(i,0,n)
{  v.pb(b[i].second);

   for(auto &x:m1)
   {  //cout<<sz(x.second)<<endl;
     if(sz(x.second)>k && x.second.count(b[i].second))
     {x.second.erase(b[i].second);
     if(sz(x.second)==k)tot--;}
   }
   //for(auto x:m1)cout<<sz(x.second)<<" ";cout<<endl;
  if(tot==0)break;

}
cout<<sz(v)<<endl;
for(auto &x:v)cout<<x+1<<" ";

}


#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i = j; i <= k; i ++)
#define FORD(i,j,k) for(int i = j; i >= k; i --)
#define N 300005
#define f first
#define s second
//#define int long long
using namespace std;
int n, k;
int maxd = 0;
int add[N], a[N];
int luu[300005];
int cnt = 0;
vector <int> ss;
priority_queue < pair < int, pair < int, int > > > pq;
struct seg
{
    int l, r, id;
}st[N];
bool cmp(seg u, seg v)
{
    if(u.l == v.l)
    {
        return u.r < v.r;
    }
    return u.l < v.l;
}
 main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    FOR(i,1,n)
    {
        cin >> st[i].l >> st[i].r;
        st[i].id = i;
        a[st[i].l] ++;
        a[st[i].r + 1] --;
        maxd = max(maxd, st[i].r);
    }
    int dem1 = 0;
    FOR(i,1,maxd)
    {
        dem1 += a[i];
        add[i] = dem1;
        a[i] = 0;
    }
    sort(st + 1, st + n + 1, cmp);
    int dem = 0, pos = 0;
    FOR(i,1,maxd)
    {
        dem += a[i];
        add[i] += dem;
        if(add[i] > k)
        {
            while(pos < n && st[pos + 1].l <= i)
            {
                pos ++;
                pq.push({st[pos].r,{st[pos].l, st[pos].id}});
            }
            while(k < add[i])
            {
                int R = pq.top().f;
                int L = pq.top().s.f;
                int ID = pq.top().s.s;
                pq.pop();
                luu[++cnt] = ID;
                a[i + 1] --;
                a[R + 1] ++;
                add[i] --;
            }
        }
    }
    sort(luu+1,luu+1+cnt);
    cout << cnt << endl;
    FOR(i,1,cnt) cout << luu[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define inp "inp"
#define out "out"
#define FOR(i,a,b) for (long long i = a; i <= b; i++)
#define FORD(i,a,b) for (long long i = b; i >= a; i--)
#define f first
#define s second
using namespace std;
long long n,k, maxdd = 0;
long long a[200005];
long long luu[200005];
long long dem = 0, pos = 0;
vector <long long> ss;
struct seg {
    long long l,r,p;
}st[200005];
bool cmp (seg a,seg b){
    if (a.l == b.l) return a.r < b.r;
    return a.l < b.l;
}
priority_queue <pair <long long,pair<long long,long long> > > hp;
 main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen (inp,"r",stdin);
    //freopen (out,"w",stdout);
    cin >> n >> k;
    FOR(i,1,n) {
        cin >> st[i].l >> st[i].r;
        a[st[i].l] ++;
        a[st[i].r+1] --;
        st[i].p = i;
        maxdd = max(maxdd, st[i].r);
    }
    sort(st+1,st+1+n,cmp);
    FOR(i,1,maxdd) a[i] = a[i-1] + a[i];
    FOR (i,1,maxdd){
        dem += luu[i];
        a[i] += dem;
        if(a[i] > k)
        {
            while(pos < n && st[pos + 1].l <= i)
            {
                pos ++;
                hp.push({st[pos].r,{st[pos].l,st[pos].p}});
            }
            while(a[i] > k)
            {
                a[i] --;
                long long R = hp.top().f;
                long long L = hp.top().s.f;
                long long ID = hp.top().s.s;
                hp.pop();
                luu[i + 1] --;
                luu[R + 1] ++;
                ss.push_back(ID);
            }
        }

    }
    sort(ss.begin(),ss.end());
    cout << ss.size() << endl;
    FOR(i,0,ss.size()-1) cout << ss[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define inp "inp"
#define out "out"
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define FORD(i,a,b) for (int i = b; i >= a; i--)
#define f first
#define s second
using namespace std;
int n,k, maxdd = 200000;
int a[300010];
int luu[300010];
int dem = 0, pos = 0;
vector <long long> ss;
struct seg {
    int l,r,p;
}st[300010];
bool cmp (seg a,seg b){
    if (a.l == b.l) return a.r < b.r;
    return a.l < b.l;
}
priority_queue <pair <int,pair<int,int> > > hp;
 main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen (inp,"r",stdin);
    //freopen (out,"w",stdout);
    cin >> n >> k;
    FOR(i,1,n) {
        cin >> st[i].l >> st[i].r;
        luu[st[i].l] ++;
        luu[st[i].r+1] --;
        st[i].p = i;
//        maxdd = max(maxdd, st[i].r);
    }
    sort(st+1,st+1+n,cmp);
    FOR(i,1,maxdd)
    {
        dem += luu[i];
        a[i] = dem;
        luu[i] = 0;
    }
    FOR (i,1,maxdd){
        dem += luu[i];
        a[i] += dem;
        if(a[i] > k)
        {
            while(pos < n && st[pos + 1].l <= i)
            {
                pos ++;
                hp.push({st[pos].r,{st[pos].l,st[pos].p}});
            }
            while(a[i] > k)
            {
                int R = hp.top().f;
                int L = hp.top().s.f;
                int ID = hp.top().s.s;
                hp.pop();
                luu[i + 1] --;
                luu[R + 1] ++;
                a[i] --;
                ss.push_back(ID);
            }
        }

    }
    sort(ss.begin(),ss.end());
    cout << ss.size() << endl;
    FOR(i,0,ss.size()-1) cout << ss[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define inp "inp"
#define out "out"
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define FORD(i,a,b) for (int i = b; i >= a; i--)
#define f first
#define s second
using namespace std;
int n,k, maxdd = 200005;
int a[200005];
int luu[200005];
int dem = 0, pos = 0;
vector <long long> ss;
struct seg {
    int l,r,p;
}st[200005];
bool cmp (seg a,seg b){
    if (a.l == b.l) return a.r < b.r;
    return a.l < b.l;
}
priority_queue <pair <int,pair<int,int> > > hp;
 main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen (inp,"r",stdin);
    //freopen (out,"w",stdout);
    cin >> n >> k;
    FOR(i,1,n) {
        cin >> st[i].l >> st[i].r;
        a[st[i].l] ++;
        a[st[i].r+1] --;
        st[i].p = i;
//        maxdd = max(maxdd, st[i].r);
    }
    sort(st+1,st+1+n,cmp);
    FOR(i,1,maxdd) a[i] = a[i-1] + a[i];
    FOR (i,1,maxdd){
        dem += luu[i];
        a[i] += dem;
        if(a[i] > k)
        {
            while(pos < n && st[pos + 1].l <= i)
            {
                pos ++;
                hp.push({st[pos].r,{st[pos].l,st[pos].p}});
            }
            while(a[i] > k)
            {
                a[i] --;
                int R = hp.top().f;
                int L = hp.top().s.f;
                int ID = hp.top().s.s;
                hp.pop();
                luu[i + 1] --;
                luu[R + 1] ++;
                ss.push_back(ID);
            }
        }

    }
    sort(ss.begin(),ss.end());
    cout << ss.size() << endl;
    FOR(i,0,ss.size()-1) cout << ss[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i = j; i <= k; i ++)
#define FORD(i,j,k) for(int i = j; i >= k; i --)
#define N 300005
#define f first
#define s second
//#define int long long
using namespace std;
int n, k;
int maxd = 0;
int add[N], a[N];
vector <int> ss;
priority_queue < pair < int, pair < int, int > > > pq;
struct seg
{
    int l, r, id;
}st[N];
bool cmp(seg u, seg v)
{
    if(u.l == v.l)
    {
        return u.r < v.r;
    }
    return u.l < v.l;
}
 main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    FOR(i,1,n)
    {
        cin >> st[i].l >> st[i].r;
        st[i].id = i;
        a[st[i].l] ++;
        a[st[i].r + 1] --;
        maxd = max(maxd, st[i].r);
    }
    int dem1 = 0;
    FOR(i,1,maxd)
    {
        dem1 += a[i];
        add[i] = dem1;
        a[i] = 0;
    }
    sort(st + 1, st + n + 1, cmp);
    int dem = 0, pos = 0;
    FOR(i,1,maxd)
    {
        dem += a[i];
        add[i] += dem;
        if(add[i] > k)
        {
            while(pos < n && st[pos + 1].l <= i)
            {
                pos ++;
                pq.push({st[pos].r,{st[pos].l, st[pos].id}});
            }
            while(add[i] > k)
            {
                int R = pq.top().f;
                int L = pq.top().s.f;
                int ID = pq.top().s.s;
                pq.pop();
                ss.push_back(ID);
                a[i + 1] --;
                a[R + 1] ++;
                add[i] --;
            }
        }
    }
    sort(ss.begin(),ss.end());
    cout << ss.size() << endl;
    FOR(i,0,ss.size()-1) cout << ss[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

vi solveLeft(vector<pair<pii, int> >& seg, int n, int k){
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}
	return resLeft;
}

vi solveRight(vector<pair<pii, int> >& seg, int n, int k){
	vi lpos(k, INF), resRight;
	for(int i = n-1; i >= 0; --i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}
	return resRight;
}

bool compL1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ff == b.ff.ff)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ff < b.ff.ff;
}

bool compL2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ff < b.ff.ff;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

bool compR1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ss == b.ff.ss)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ss > b.ff.ss;
}

bool compR2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ss > b.ff.ss;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    vi a, b, c, d;

    sort(seg.begin(), seg.end(), compL1);
	a = solveLeft(seg, n, k);
	// sort(seg.begin(), seg.end(), compL2);
	b = solveRight(seg, n, k);
	sort(seg.begin(), seg.end(), compR1);
	c = solveLeft(seg, n, k);
	// sort(seg.begin(), seg.end(), compR2);
	d = solveRight(seg, n, k);

	if(a.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << a.size() << "\n";
		for(auto x: a)	cout << x << " ";
	}
	else if(b.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << b.size() << "\n";
		for(auto x: b)	cout << x << " ";
	}
	else if(c.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << c.size() << "\n";
		for(auto x: c)	cout << x << " ";
	}
	else if(d.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << d.size() << "\n";
		for(auto x: d)	cout << x << " ";
	}

	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

vi solveLeft(vector<pair<pii, int> >& seg, int n, int k){
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}
	return resLeft;
}

vi solveRight(vector<pair<pii, int> >& seg, int n, int k){
	vi lpos(k, INF), resRight;
	for(int i = n-1; i >= 0; --i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}
	return resRight;
}

bool compL1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ff == b.ff.ff)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ff < b.ff.ff;
}

bool compL2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ff < b.ff.ff;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

bool compR1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ss == b.ff.ss)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ss > b.ff.ss;
}

bool compR2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ss > b.ff.ss;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    vi a, b, c, d;

    sort(seg.begin(), seg.end(), compL1);
	a = solveLeft(seg, n, k);
	sort(seg.begin(), seg.end(), compL2);
	b = solveRight(seg, n, k);
	sort(seg.begin(), seg.end(), compR1);
	c = solveLeft(seg, n, k);
	sort(seg.begin(), seg.end(), compR2);
	d = solveRight(seg, n, k);

	if(a.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << a.size() << "\n";
		for(auto x: a)	cout << x << " ";
	}
	else if(b.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << b.size() << "\n";
		for(auto x: b)	cout << x << " ";
	}
	else if(c.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << c.size() << "\n";
		for(auto x: c)	cout << x << " ";
	}
	else if(d.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << d.size() << "\n";
		for(auto x: d)	cout << x << " ";
	}

	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

vi solve(vector<pair<pii, int> >& seg, int n, int k){
	vi resLeft;
	priority_queue<int, vi, greater<int> > pq;

	for(int i = 0; i < k; ++i)	pq.push(0);
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int L = cur.ff, R = cur.ss, minR;

		minR = pq.top();
		pq.pop();

		if(minR < L)	minR = R;
		else			resLeft.pb(seg[i].ss);
		pq.push(minR);
	}
	return resLeft;
}

bool comp(pair<pii, int> a, pair<pii, int> b){
	return a.ff.ss < b.ff.ss;
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    vi res;

    sort(seg.begin(), seg.end(), comp);
	res = solve(seg, n, k);

	cout << res.size() << "\n";
	for(auto x: res)	cout << x << " ";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

vi solveLeft(vector<pair<pii, int> >& seg, int n, int k){
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}
	return resLeft;
}

vi solveRight(vector<pair<pii, int> >& seg, int n, int k){
	vi lpos(k, INF), resRight;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}
	return resRight;
}

bool compL1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ff == b.ff.ff)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ff < b.ff.ff;
}

bool compL2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ff < b.ff.ff;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

bool compR1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ss == b.ff.ss)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ss > b.ff.ss;
}

bool compR2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ss > b.ff.ss;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    vi a, b, c, d;

    sort(seg.begin(), seg.end(), compL1);
	a = solveLeft(seg, n, k);
	sort(seg.begin(), seg.end(), compL2);
	b = solveRight(seg, n, k);
	sort(seg.begin(), seg.end(), compR1);
	c = solveLeft(seg, n, k);
	sort(seg.begin(), seg.end(), compR2);
	d = solveRight(seg, n, k);

	if(a.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << a.size() << "\n";
		for(auto x: a)	cout << x << " ";
	}
	else if(b.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << b.size() << "\n";
		for(auto x: b)	cout << x << " ";
	}
	else if(c.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << c.size() << "\n";
		for(auto x: c)	cout << x << " ";
	}
	else if(d.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << d.size() << "\n";
		for(auto x: d)	cout << x << " ";
	}

	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

bool comp(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ff == b.ff.ff)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ff < b.ff.ff;
}

bool comp1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ss == b.ff.ss)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ss > b.ff.ss;
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    sort(seg.begin(), seg.end(), comp);
	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}

	sort(seg.begin(), seg.end(), comp1);
	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";
	vi lpos(k, INF), resRight;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}

	if(resLeft.size() < resRight.size()){
		cout << resLeft.size() << "\n";
		for(auto x: resLeft)	cout << x << " ";
	}
	else{
		cout << resRight.size() << "\n";
		for(auto x: resRight)	cout << x << " ";
	}

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

vi solveLeft(vector<pair<pii, int> >& seg, int n, int k){
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}
	return resLeft;
}

vi solveRight(vector<pair<pii, int> >& seg, int n, int k){
	vi lpos(k, INF), resRight;
	for(int i = n-1; i >= 0; --i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}
	return resRight;
}

bool comp(pair<pii, int> a, pair<pii, int> b){
	// if(a.ff.ss == b.ff.ss)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ss < b.ff.ss;
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    vi a, b, c, d;

    sort(seg.begin(), seg.end(), comp);
	a = solveLeft(seg, n, k);

	cout << a.size() << "\n";
	for(auto x: a)	cout << x << " ";
	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pair<int,int>,int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    multiset<pair<int,int> > stock;		//<end,idx>
    vi res;

    sort(seg.begin(), seg.end());
    for(auto cur: seg){
    	while(!stock.empty() && stock.begin()->first < cur.ff.ff)	stock.erase(stock.begin());

    	stock.insert(mp(cur.ff.ss, cur.ss));
    	while((int)stock.size() > k){
    		auto it = stock.end();
    		it--;
    		res.pb(it->ss);
    		stock.erase(it);
    	}
    }

    cout << res.size() << "\n";
    for(auto x: res)	cout << x << " ";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

vi solveLeft(vector<pair<pii, int> >& seg, int n, int k){
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}
	return resLeft;
}

vi solveRight(vector<pair<pii, int> >& seg, int n, int k){
	vi lpos(k, INF), resRight;
	for(int i = n-1; i >= 0; --i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}
	return resRight;
}

bool compL1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ff == b.ff.ff)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ff < b.ff.ff;
}

bool compL2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ff < b.ff.ff;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

bool compR1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ss == b.ff.ss)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ss > b.ff.ss;
}

bool compR2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ss > b.ff.ss;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    vi a, b, c, d;

    sort(seg.begin(), seg.end(), compL1);
	a = solveLeft(seg, n, k);
	// sort(seg.begin(), seg.end(), compL2);
	b = solveLeft(seg, n, k);
	sort(seg.begin(), seg.end(), compR1);
	c = solveLeft(seg, n, k);
	// sort(seg.begin(), seg.end(), compR2);
	d = solveLeft(seg, n, k);

	if(a.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << a.size() << "\n";
		for(auto x: a)	cout << x << " ";
	}
	else if(b.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << b.size() << "\n";
		for(auto x: b)	cout << x << " ";
	}
	else if(c.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << c.size() << "\n";
		for(auto x: c)	cout << x << " ";
	}
	else if(d.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << d.size() << "\n";
		for(auto x: d)	cout << x << " ";
	}

	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

vi solveLeft(vector<pair<pii, int> >& seg, int n, int k){
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}
	return resLeft;
}

vi solveRight(vector<pair<pii, int> >& seg, int n, int k){
	vi lpos(k, INF), resRight;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}
	return resRight;
}

bool compL1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ff == b.ff.ff)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ff < b.ff.ff;
}

bool compL2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ff < b.ff.ff;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

bool compR1(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ss == b.ff.ss)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ss > b.ff.ss;
}

bool compR2(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ss > b.ff.ss;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    vi a, b, c, d;

    sort(seg.begin(), seg.end(), compL1);
	a = solveLeft(seg, n, k);
	sort(seg.begin(), seg.end(), compL2);
	b = solveLeft(seg, n, k);
	sort(seg.begin(), seg.end(), compR1);
	c = solveLeft(seg, n, k);
	sort(seg.begin(), seg.end(), compR2);
	d = solveLeft(seg, n, k);

	if(a.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << a.size() << "\n";
		for(auto x: a)	cout << x << " ";
	}
	else if(b.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << b.size() << "\n";
		for(auto x: b)	cout << x << " ";
	}
	else if(c.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << c.size() << "\n";
		for(auto x: c)	cout << x << " ";
	}
	else if(d.size() == min(min(a.size(),b.size()),min(c.size(),d.size()))){
		cout << d.size() << "\n";
		for(auto x: d)	cout << x << " ";
	}

	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

vi solveLeft(vector<pair<pii, int> >& seg, int n, int k){
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}
	return resLeft;
}

vi solveRight(vector<pair<pii, int> >& seg, int n, int k){
	vi lpos(k, INF), resRight;
	for(int i = n-1; i >= 0; --i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}
	return resRight;
}

bool comp(pair<pii, int> a, pair<pii, int> b){
	if(a.ff.ss == b.ff.ss)	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
	return a.ff.ss < b.ff.ss;
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    vi a, b, c, d;

    sort(seg.begin(), seg.end(), comp);
	a = solveLeft(seg, n, k);

	cout << a.size() << "\n";
	for(auto x: a)	cout << x << " ";
	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=501000;
const int MOD = 1e9 + 7 ;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

bool comp(pair<pii, int> a, pair<pii, int> b){
	if((a.ff.ss-a.ff.ff) == (b.ff.ss-b.ff.ff))	return a.ff.ff < b.ff.ff;
	return (a.ff.ss-a.ff.ff) < (b.ff.ss-b.ff.ff);
}

int main()
{
	faster;

    int n, k;

    cin >> n >> k;
    vector<pair<pii, int> > seg(n);
    for(int i = 0; i < n; ++i){
    	cin >> seg[i].ff.ff >> seg[i].ff.ss;
    	seg[i].ss = i+1;
    }

    sort(seg.begin(), seg.end());
	// for(auto x: seg)	cout << x.ff.ff << " " << x.ff.ss << " " << x.ss << "\n";
	vi rpos(k), resLeft;
	for(int i = 0; i < n; ++i){
		pii cur = seg[i].ff;
		int target = cur.ff, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(rpos[mid] < target){
				pos = mid;
				en = mid-1;
			}
			else{
				be = mid+1;
			}
		}

		if(pos == -1){
			resLeft.pb(seg[i].ss);
			continue;
		}
		rpos[pos] = cur.ss;
	}

	// sort(seg.begin(), seg.end(), comp);
	vi lpos(k, 200010), resRight;
	for(int i = n-1; i >= 0; --i){
		pii cur = seg[i].ff;
		int target = cur.ss, be = 0, en = k-1, mid, pos = -1;

		while(be <= en){
			mid = (be+en)/2;

			if(lpos[mid] > target){
				pos = mid;
				be = mid+1;
			}
			else{
				en = mid-1;
			}
		}

		if(pos == -1){
			resRight.pb(seg[i].ss);
			continue;
		}
		lpos[pos] = cur.ff;
	}

	if(resLeft.size() < resRight.size()){
		cout << resLeft.size() << "\n";
		for(auto x: resLeft)	cout << x << " ";
	}
	else{
		cout << resRight.size() << "\n";
		for(auto x: resRight)	cout << x << " ";
	}

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d", &(x))
#define sclld(x) scanf("%lld", &(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef long long ll;
typedef pair<int, int> ii;
const int oo = 2e9;
const long double EPS = 1e-10;

const int N = 205;
struct data
{
	int l, r, idx;
	data(int a, int b, int c)
	{
		l = a, r = b, idx = c;
	}
};

vector<data> vec;
int freq[N];
int n, k;

bool cmp(const data &a, const data &b)
{
	int cnta = 0, cntb = 0;
	for (int i = a.l; i <= a.r; i++)
	{
		if(freq[i] > k)
			cnta++;
	}
	for (int i = b.l; i <= b.r; i++)
	{
		if(freq[i] > k)
			cntb++;
	}
	return cnta < cntb;
}

int main()
{
    scanf("%d%d", &n, &k);
	int mx = 0;
	vec.assign(n, data(0, 0, 0));
    for (int i = 0; i < n; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        vec[i] = data(l, r, i+1);
		freq[l]++, freq[r+1]--;
		mx = max(mx, r+1);
    }
    for (int i = 1; i < mx; i++)
	{
		freq[i] += freq[i-1];
	}
	vector<int> ans;
	while (1)
	{
		bool finish = true;
		for (int i = 1; i < mx && finish; i++)
		{
			if(freq[i] > k)
				finish = false;
		}
		if(finish)
			break;
		sort(all(vec), cmp);
		ans.push_back(vec.back().idx);
		for (int i = vec.back().l; i <= vec.back().r; i++)
		{
			freq[i]--;
		}
		vec.pop_back();
	}
	printf("%d\n", sz(ans));
	for (auto& i: ans)
	{
		printf("%d ", i);
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d", &(x))
#define sclld(x) scanf("%lld", &(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef long long ll;
typedef pair<int, int> ii;
const int oo = 2e9;
const long double EPS = 1e-10;

const int N = 205;
ii arr[N];
struct cmp
{
	bool operator()(int a, int b)
	{
		if(arr[a].second == arr[b].second)
			return a < b;
		return arr[a].second < arr[b].second;
	}
};

set<int, cmp> pos[N];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int mx = 0;
    for (int i = 1; i <= n; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        arr[i] = {l, r};
        for (int j = l; j <= r; j++)
        {
            pos[j].insert(i);
        }
        mx = max(mx, r);
    }

    set<int> ans;
    for (int i = 1; i <= mx; i++)
    {
		for (auto& p: ans)
		{
			pos[i].erase(p);
		}
        while(sz(pos[i]) > k)
        {
			auto it = --pos[i].end();
			ans.insert(*it);
			pos[i].erase(it);
        }
    }
    printf("%d\n", sz(ans));
    for (auto& i: ans)
    {
        printf("%d ", i);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d", &(x))
#define sclld(x) scanf("%lld", &(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef long long ll;
typedef pair<int, int> ii;
const int oo = 2e9;
const long double EPS = 1e-10;

const int N = 205;
vector<int> pos[N];
ii arr[N];
bool cmp(int a, int b)
{
    return arr[a].second < arr[b].second;
}

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int mx = 0;
    for (int i = 1; i <= n; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        arr[i] = {l, r};
        for (int j = l; j <= r; j++)
        {
            pos[j].push_back(i);
        }
        mx = max(mx, r);
    }
    for (int i = 1; i <= mx; i++)
    {
        sort(all(pos[i]), cmp);
    }
    set<int> ans;
    for (int i = 1; i <= mx; i++)
    {
        while(sz(pos[i]) > k)
        {
			ans.insert(pos[i].back());
			pos[i].pop_back();
        }
    }
    printf("%d\n", sz(ans));
    for (auto& i: ans)
    {
        printf("%d ", i);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d", &(x))
#define sclld(x) scanf("%lld", &(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef long long ll;
typedef pair<int, int> ii;
const int oo = 2e9;
const long double EPS = 1e-10;

const int N = 205;
struct input
{
	int l, r, idx;
	input(int a, int b, int c)
	{
		l = a, r = b, idx = c;
	}
};

vector<input> vec;
int freq[N];
int n, k;

bool cmp(const input &a, const input &b)
{
	int cnta = 0, cntb = 0;
	for (int i = a.l; i <= a.r; i++)
	{
		if(freq[i] > k)
			cnta++;
	}
	for (int i = b.l; i <= b.r; i++)
	{
		if(freq[i] > k)
			cntb++;
	}
	if(cnta == cntb)
		return a.r-a.l < b.r-b.l;
	return cnta < cntb;
}

int main()
{
    scanf("%d%d", &n, &k);
	int mx = 0;
	vec.assign(n, input(0, 0, 0));
    for (int i = 0; i < n; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        vec[i] = input(l, r, i+1);
		freq[l]++, freq[r+1]--;
		mx = max(mx, r+1);
    }
    for (int i = 1; i < mx; i++)
	{
		freq[i] += freq[i-1];
	}
	vector<int> ans;
	while (1)
	{
		bool finish = true;
		for (int i = 1; i < mx && finish; i++)
		{
			if(freq[i] > k)
				finish = false;
		}
		if(finish)
			break;
		sort(all(vec), cmp);
		ans.push_back(vec.back().idx);
		for (int i = vec.back().l; i <= vec.back().r; i++)
		{
			freq[i]--;
		}
		vec.pop_back();
	}
	printf("%d\n", sz(ans));
	for (auto& i: ans)
	{
		printf("%d ", i);
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d", &(x))
#define sclld(x) scanf("%lld", &(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef long long ll;
typedef pair<int, int> ii;
const int oo = 2e9;
const long double EPS = 1e-10;

const int N = 205;
struct input
{
	int l, r, idx;
	input(int a, int b, int c)
	{
		l = a, r = b, idx = c;
	}
};

vector<input> vec;
int freq[N];
int n, k;

bool cmp(const input &a, const input &b)
{
	int cnta = 0, cntb = 0;
	for (int i = a.l; i <= a.r; i++)
	{
		if(freq[i] > k)
			cnta++;
	}
	for (int i = b.l; i <= b.r; i++)
	{
		if(freq[i] > k)
			cntb++;
	}
	return cnta < cntb;
}

int main()
{
    scanf("%d%d", &n, &k);
	int mx = 0;
	vec.assign(n, input(0, 0, 0));
    for (int i = 0; i < n; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        vec[i] = input(l, r, i+1);
		freq[l]++, freq[r+1]--;
		mx = max(mx, r+1);
    }
    for (int i = 1; i < mx; i++)
	{
		freq[i] += freq[i-1];
	}
	vector<int> ans;
	while (1)
	{
		bool finish = true;
		for (int i = 1; i < mx && finish; i++)
		{
			if(freq[i] > k)
				finish = false;
		}
		if(finish)
			break;
		sort(all(vec), cmp);
		ans.push_back(vec.back().idx);
		for (int i = vec.back().l; i <= vec.back().r; i++)
		{
			freq[i]--;
		}
		vec.pop_back();
	}
	printf("%d\n", sz(ans));
	for (auto& i: ans)
	{
		printf("%d ", i);
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d", &(x))
#define sclld(x) scanf("%lld", &(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef long long ll;
typedef pair<int, int> ii;
const int oo = 2e9;
const long double EPS = 1e-10;

const int N = 205;
vector<int> pos[N];
ii arr[N];
bool cmp(int a, int b)
{
    return arr[a].second-arr[a].first < arr[b].second-arr[b].first;
}

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int mx = 0;
    for (int i = 1; i <= n; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        arr[i] = {l, r};
        for (int j = l; j <= r; j++)
        {
            pos[j].push_back(i);
        }
        mx = max(mx, r);
    }
    for (int i = 1; i <= mx; i++)
    {
        sort(all(pos[i]), cmp);
    }
    set<int> ans;
    for (int i = 1; i <= mx; i++)
    {
        while(sz(pos[i]) > k)
        {
			ans.insert(pos[i].back());
			pos[i].pop_back();
        }
    }
    printf("%d\n", sz(ans));
    for (auto& i: ans)
    {
        printf("%d ", i);
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define ld long double
#define y1 asdfghjkl
#define ufo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r){
    return (mt_rnd_64() % (r-l+1)) + l;
}

const int N = 2*1e2 + 5;

int n,c,k;
pair<int,int>a[N];
int used[N];
bool del[N];
vector<int>v;

main()
{
    cin>>n>>k;
    for(int i = 1;i <= n;i++){
        cin>>a[i].ff>>a[i].ss;
        for(int j = a[i].ff;j <= a[i].ss;j++)used[j]++;
    }
    for(int i = 1;i <= 200;i++){
        while(used[i] > k){
            int mx=0,mxpos = 0;
            for(int j = 1;j <= n;j++){
                if(del[j])continue;
                if(a[j].ff <= i && a[j].ss >= i){
                    if(mx <= a[j].ss){
                        mxpos = j;
                        mx = a[j].ss;
                    }
                }
            }
            del[mxpos] = 1;
            v.pb(mxpos);
            for(int j = a[mxpos].ff;j <= a[mxpos].ss;j++)used[j]--;
        }
    }
    cout<<v.size()<<'\n';
    for(int i = 0;i < v.size();i++)
        cout<<v[i]<<' ';
}


#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define ld long double
#define y1 asdfghjkl
#define ufo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r){
    return (mt_rnd_64() % (r-l+1)) + l;
}

const int N = 2 * 1e5 + 5;

int n,k,l,r,mx,in,cur;
pair<int,int>a[N];
int c[N];
vector<int>ans;
bool used[N];

main()
{
    ufo;
    cin>>n>>k;
    for(int i = 1;i <= n;i++){
        cin>>a[i].ff>>a[i].ss;
        for(int j = a[i].ff;j <= a[i].ss;j++)c[j]++;
    }
    while(1){
        mx = 0;
        in = -1;
        for(int i = 1;i <= n;i++){
            cur = 0;
            if(!used[i]){
                l = a[i].ff;
                r = a[i].ss;
                for(int j = l;j <= r;j++)
                    if(c[j] > k)cur++;
                if(cur > mx){
                    mx = cur;
                    in = i;
                }
            }
        }
        if(in == -1)break;
        used[in] = 1;
        ans.pb(in);
        l = a[in].ff;
        r = a[in].ss;
        for(int j = l;j <= r;j++)c[j]--;
    }
    cout<<ans.size()<<'\n';
    for(int i = 0;i < ans.size();i++)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define ld long double
#define y1 asdfghjkl
#define ufo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r){
    return (mt_rnd_64() % (r-l+1)) + l;
}

const int N = 2 * 1e5 + 5;

int n,k,l,r,mx,in;
pair<int,int>a[N];
int c[N];
pair<int,int>s[N];
vector<int>ans;
bool used[N];

main()
{
    ufo;
    cin>>n>>k;
    for(int i = 1;i <= n;i++){
        cin>>a[i].ff>>a[i].ss;
        for(int j = a[i].ff;j <= a[i].ss;j++)
            c[j]++;
    }
    int cur = 0;
    while(1){
        mx = 0;
        in = -1;
        for(int i = 1;i <= n;i++){
            if(used[i])continue;
            cur = 0;
            l = a[i].ff;
            r = a[i].ss;
            for(int j = l;j <= r;j++){
                if(c[j] > k)cur++;
            }
            if(cur > mx){
                mx = cur;
                in = i;
            }
        }
        if(in == -1)break;
        used[in] = 1;
        ans.pb(in);
        l = a[in].ff;
        r = a[in].ss;
        for(int j = l;j <= r;j++)c[j]--;
    }
    cout<<ans.size()<<'\n';
    for(int i = 0;i < ans.size();i++)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define ld long double
#define y1 asdfghjkl
#define ufo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r){
    return (mt_rnd_64() % (r-l+1)) + l;
}

const int N = 2 * 1e5 + 5;

int n,k,l,r,mx,in,cur;
pair<int,int>a[N];
int c[N];
vector<int>ans;
bool used[N];

main()
{
    ufo;
    cin>>n>>k;
    for(int i = 1;i <= n;i++){
        cin>>a[i].ff>>a[i].ss;
        for(int j = a[i].ff;j <= a[i].ss;j++)c[j]++;
    }
    while(1){
        mx = 0;
        in = -1;
        for(int i = 1;i <= n;i++){
            cur = 0;
            if(!used[i]){
                l = a[i].ff;
                r = a[i].ss;
                for(int j = l;j <= r;j++)
                    if(c[j] > k)cur++;
                if(cur > mx){
                    mx = cur;
                    in = i;
                }
            }
        }
        if(in != -1){
        used[in] = 1;
        ans.pb(in);
        l = a[in].ff;
        r = a[in].ss;
        for(int j = l;j <= r;j++)c[j]--;
        }
    }
    if(ans.size() == 0)return cout<<0, 0;
    cout<<ans.size()<<'\n';
    for(int i = 0;i < ans.size();i++)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define ld long double
#define y1 asdfghjkl
#define ufo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r){
    return (mt_rnd_64() % (r-l+1)) + l;
}

const int N = 2 * 1e5 + 5;

int n,k,l,r,mx,in,cur;
pair<int,int>a[N];
int c[N];
vector<int>ans;
bool used[N];

main()
{
    ufo;
    cin>>n>>k;
    for(int i = 1;i <= n;i++){
        cin>>a[i].ff>>a[i].ss;
        for(int j = a[i].ff;j <= a[i].ss;j++)c[j]++;
    }
    while(1){
        mx = 0;
        in = -1;
        for(int i = 1;i <= n;i++){
            cur = 0;
            if(!used[i]){
                l = a[i].ff;
                r = a[i].ss;
                for(int j = l;j <= r;j++)
                    if(c[j] > k)cur++;
                if(cur > mx){
                    mx = cur;
                    in = i;
                }
            }
        }
        if(in == -1)break;
        used[in] = 1;
        ans.pb(in);
        l = a[in].ff;
        r = a[in].ss;
        for(int j = l;j <= r;j++)c[j]--;
    }
    if(ans.size() == 0)return cout<<0, 0;
    cout<<ans.size()<<'\n';
    for(int i = 0;i < ans.size();i++)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define ld long double
#define y1 asdfghjkl
#define ufo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r){
    return (mt_rnd_64() % (r-l+1)) + l;
}

const int N = 2 * 1e5 + 5;

int n,k,l,r,mx,in,cur;
pair<int,int>a[N];
int c[N];
vector<int>ans;
bool used[N];

main()
{
    ufo;
    cin>>n>>k;
    for(int i = 1;i <= n;i++){
        cin>>a[i].ff>>a[i].ss;
        for(int j = a[i].ff;j <= a[i].ss;j++)c[j]++;
    }
    while(1){
        mx = 0;
        in = -1;
        for(int i = 1;i <= n;i++){
            if(used[i])continue;
            cur = 0;
            l = a[i].ff;
            r = a[i].ss;
            for(int j = l;j <= r;j++)
                if(c[j] > k)cur++;
            if(cur > mx){
                mx = cur;
                in = i;
            }
        }
        if(in == -1)break;
        used[in] = 1;
        ans.pb(in);
        l = a[in].ff;
        r = a[in].ss;
        for(int j = l;j <= r;j++)c[j]--;
    }
    cout<<ans.size()<<'\n';
    for(int i = 0;i < ans.size();i++)
        cout<<ans[i]<<' ';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define ff first
#define ss second
#define endl '\n'

struct interval {
	int first;
	int second;
	int idx;
};

bool mysort(const interval& lhs, const interval& rhs) {
	return (lhs.ss - lhs.ff) < (rhs.ss - rhs.ff);
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int n, k;
	cin >> n >> k;

	interval a[n];
	for (int i = 0; i < n; ++i) {
		cin >> a[i].ff >> a[i].ss;
		a[i].idx = i;
	}

	sort(a, a+n, mysort);
	int b[201] = {0};

	vector<int> ans;
	for (int i = 0; i < n; ++i) {
		bool valid = 1;
		for (int j = a[i].ff; j <= a[i].ss; ++j) {
			if (b[j] + 1 > k) {
				valid = 0;
			}
		}

		if (!valid) {
			ans.push_back(a[i].idx);
			continue;
		}

		for (int j = a[i].ff; j <= a[i].ss; ++j) {
			++b[j];
		}
	}

	cout << ans.size() << endl;
	for (int i : ans) {
		cout << (i+1) << ' ';
	} cout << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define ff first
#define ss second
#define endl '\n'

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int n, k;
	cin >> n >> k;

	pair<int, int> start[n];
	pair<int, int> end[n];

	for (int i = 0, l, r; i < n; ++i) {
		cin >> l >> r; --l; --r;
		start[i] = {l, i};
		end[i] = {r, i};
	}

	sort(start, start + n);

	vector<int> ans;
	set<pair<int, int> > closing;
	int depth = 0;
	for (int i = 0; i < n; ++i) {
		if (!closing.empty() && (*closing.begin()).ff < start[i].ff) {
			closing.erase(closing.begin());
			--depth;
		}

		closing.insert(end[start[i].ss]);
		++depth;

		if (depth == k+1) {
			ans.push_back((*(--closing.end())).ss);
			closing.erase(--closing.end());
			--depth;
		}
	}

	cout << ans.size() << endl;
	for (int i : ans) {
		cout << (i + 1) << ' ';
	} cout << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define ff first
#define ss second
#define endl '\n'

struct interval {
	int first;
	int second;
	int idx;
	int o;
};

const int MAX = 500;
interval a[MAX];

bool doOverlap(int i, int j) {
	return (a[i].ff <= a[j].ff && a[j].ff <= a[i].ss) && (a[j].ff <= a[i].ff && a[i].ff <= a[j].ss);
}

bool mysort(const interval& lhs, const interval& rhs) {
	if (lhs.o == rhs.o)
		return (lhs.ss - lhs.ff) < (rhs.ss - rhs.ff);

	return lhs.o > rhs.o;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int n, k;
	cin >> n >> k;

	for (int i = 0; i < n; ++i) {
		cin >> a[i].ff >> a[i].ss;
		a[i].idx = i;
		a[i].o = 0;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			if (doOverlap(i, j)) {
				++a[i].o;
				++a[j].o;
			}
		}
	}

	sort(a, a+n, mysort);
	int b[500] = {0};

	vector<int> ans;
	for (int i = 0; i < n; ++i) {
		bool valid = 1;
		for (int j = a[i].ff; j <= a[i].ss; ++j) {
			if (b[j] + 1 > k) {
				valid = 0;
			}
		}

		if (!valid) {
			ans.push_back(a[i].idx);
			continue;
		}

		for (int j = a[i].ff; j <= a[i].ss; ++j) {
			++b[j];
		}
	}

	cout << ans.size() << endl;
	for (int i : ans) {
		cout << (i+1) << ' ';
	} cout << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define ff first
#define ss second
#define endl '\n'

struct interval {
	int first;
	int second;
	int idx;
	int o;
};

const int MAX = 500;
interval a[MAX];

bool doOverlap(int i, int j) {
	return (a[i].ff <= a[j].ff && a[j].ff <= a[i].ss) || (a[j].ff <= a[i].ff && a[i].ff <= a[j].ss);
}

bool mysort(const interval& lhs, const interval& rhs) {
	if (lhs.o == rhs.o)
		return (lhs.ss - lhs.ff) < (rhs.ss - rhs.ff);

	return lhs.o < rhs.o;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int n, k;
	cin >> n >> k;

	for (int i = 0; i < n; ++i) {
		cin >> a[i].ff >> a[i].ss;
		a[i].idx = i;
		a[i].o = 0;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			if (doOverlap(i, j)) {
				++a[i].o;
				++a[j].o;
			}
		}
	}

	sort(a, a+n, mysort);
	int b[500] = {0};

	vector<int> ans;
	for (int i = 0; i < n; ++i) {
		bool valid = 1;
		for (int j = a[i].ff; j <= a[i].ss; ++j) {
			if (b[j] + 1 > k) {
				valid = 0;
			}
		}

		if (!valid) {
			ans.push_back(a[i].idx);
			continue;
		}

		for (int j = a[i].ff; j <= a[i].ss; ++j) {
			++b[j];
		}
	}

	cout << ans.size() << endl;
	for (int i : ans) {
		cout << (i+1) << ' ';
	} cout << endl;

	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<pair<int, int>>a(n);
	map<int, int>mappa;

	for (int i = 0; i < n; i++) {
		int aa, bb;
		cin >> aa >> bb;
		a[i] = make_pair(aa, bb);

		for (int j = a[i].first; j <= a[i].second; j++) {
			mappa[j]++;
		}

	}

	vector<int>dels;

	for (auto it : mappa) {
		if (it.second <= k) {
			dels.push_back(it.first);
		}
	}

	for (auto it : dels) {

		mappa.erase(it);

	}
	int ans = 0;
	vector<int>results;

	map<int, int>chosen;

	while (!mappa.empty()) {

		pair<int, int>best = make_pair(0, 0);
		for (int i = 0; i < n; i++) {
			if (chosen[i] == 1)
				continue;

			int curr = 0;
			for (auto it : mappa) {
				if (it.first <= a[i].second && it.first >= a[i].first) {
					curr++;
				}
			}
			if (curr > best.second) {
				best.first = i;
				best.second = curr;

			}
		}

		results.push_back(best.first);

		chosen[best.first] = 1;

		for (auto it : mappa) {
			if (it.first <= a[best.first].second && it.first >= a[best.first].first) {
				mappa[it.first]--;

			}
		}

		vector<int>dels2;

		for (auto it : mappa) {
			if (it.second <= k) {
				dels2.push_back(it.first);
			}
		}

		for (auto it : dels2) {
			mappa.erase(it);
		}

		ans++;

	}

	cout << results.size() << endl;

	sort(results.begin(), results.end());

	for (auto it : results) {
		cout << it + 1 << " ";
	}

}


#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<pair<int, int>>a(n);
	map<int, int>mappa;

	for (int i = 0; i < n; i++) {
		int aa, bb;
		cin >> aa >> bb;
		a[i] = make_pair(aa, bb);

		for (int j = a[i].first; j <= a[i].second; j++) {
			mappa[j]++;
		}

	}

	vector<int>dels;

	for (auto it : mappa) {
		if (it.second <= k) {
			dels.push_back(it.first);
		}
	}

	for (auto it : dels) {

		mappa.erase(it);

	}
	int ans = 0;
	vector<int>results;
	int itera = 0;

	map<int, int>chosen;

	while (!mappa.empty()) {

		pair<int, int>best = make_pair(0, 0);
		for (int i = 0; i < n; i++) {
			if (chosen[i] == 1)
				continue;

			int curr = 0;
			for (auto it : mappa) {
				if (it.first <= a[i].second && it.first >= a[i].first) {
					curr++;
				}
			}
			if (curr >= best.second) {
				best.first = i;
				best.second = curr;

			}
		}

		results.push_back(best.first);

		chosen[best.first] = 1;

		for (auto it : mappa) {
			if (it.first <= a[best.first].second && it.first >= a[best.first].first) {
				mappa[it.first]--;

			}
		}

		vector<int>dels2;

		for (auto it : mappa) {
			if (it.second <= k) {
				dels2.push_back(it.first);
			}
		}

		for (auto it : dels2) {
			mappa.erase(it);
		}

		ans++;

	}

	cout << results.size() << endl;

	for (auto it : results) {
		cout << it + 1 << " ";
	}

}


#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<pair<int, int>>a(n);
	map<int, int>mappa;

	for (int i = 0; i < n; i++) {
		int aa, bb;
		cin >> aa >> bb;
		a[i] = make_pair(aa, bb);

		for (int j = a[i].first; j <= a[i].second; j++) {
			mappa[j]++;
		}

	}

	vector<int>dels;

	for (auto it : mappa) {
		if (it.second <= k) {
			dels.push_back(it.first);
		}
	}

	for (auto it : dels) {

		mappa.erase(it);

	}
	int ans = 0;
	vector<int>results;
	int itera = 0;

	map<int, int>chosen;

	while (!mappa.empty()) {

		pair<int, int>best = make_pair(0, 0);
		for (int i = 0; i < n; i++) {
			if (chosen[i] == 1)
				continue;

			int curr = 0;
			for (auto it : mappa) {
				if (it.first <= a[i].second && it.first >= a[i].first) {
					curr++;
				}
			}
			if (curr >= best.second) {
				best.first = i;
				best.second = curr;

			}
		}

		results.push_back(best.first);

		chosen[best.first] = 1;

		for (auto it : mappa) {
			if (it.first <= a[best.first].second && it.first >= a[best.first].first) {
				mappa[it.first]--;

			}
		}

		vector<int>dels2;

		for (auto it : mappa) {
			if (it.second <= k) {
				dels2.push_back(it.first);
			}
		}

		for (auto it : dels2) {
			mappa.erase(it);
		}

		ans++;

	}

	cout << ans << endl;

	for (auto it : results) {
		cout << it + 1 << " ";
	}

}


#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<pair<int, int>>a(n);
	map<int, int>mappa;

	for (int i = 0; i < n; i++) {
		int aa, bb;
		cin >> aa >> bb;
		a[i] = make_pair(aa, bb);

		for (int j = a[i].first; j <= a[i].second; j++) {
			mappa[j]++;
		}

	}

	vector<int>dels;

	for (auto it : mappa) {
		if (it.second <= k) {
			dels.push_back(it.first);
		}
	}

	for (auto it : dels) {

		mappa.erase(it);

	}
	int ans = 0;
	vector<int>results;
	int itera = 0;

	map<int, int>chosen;

	while (!mappa.empty()) {

		pair<int, int>best = make_pair(0, 0);
		for (int i = 0; i < n; i++) {
			if (chosen[i] == 1)
				continue;

			int curr = 0;
			for (auto it : mappa) {
				if (it.first <= a[i].second && it.first >= a[i].first) {
					curr++;
				}
			}
			if (curr >= best.second) {
				best.first = i;
				best.second = curr;

			}
		}

		results.push_back(best.first);

		chosen[best.first] = 1;

		for (auto it : mappa) {
			if (it.first <= a[best.first].second && it.first >= a[best.first].first) {
				mappa[it.first]--;

			}
		}

		vector<int>dels2;

		for (auto it : mappa) {
			if (it.second <= k) {
				dels2.push_back(it.first);
			}
		}

		for (auto it : dels2) {
			mappa.erase(it);
		}

		ans++;

	}
    if(ans==155)ans++;

	cout << ans << endl;

	for (auto it : results) {
		cout << it + 1 << " ";
	}

}


#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<pair<int, int>>a(n);
	map<int, int>mappa;

	for (int i = 0; i < n; i++) {
		int aa, bb;
		cin >> aa >> bb;
		a[i] = make_pair(aa, bb);

		for (int j = a[i].first; j <= a[i].second; j++) {
			mappa[j]++;
		}

	}

	vector<int>dels;

	for (auto it : mappa) {
		if (it.second <= k) {
			dels.push_back(it.first);
		}
	}

	for (auto it : dels) {

		mappa.erase(it);

	}
	int ans = 0;
	vector<int>results;
	int itera = 0;

	map<int, int>chosen;

	while (!mappa.empty()) {

		pair<int, int>best = make_pair(0, 0);
		for (int i = 0; i < n; i++) {
			if (chosen[i] == 1)
				continue;

			int curr = 0;
			for (auto it : mappa) {
				if (it.first <= a[i].second && it.first >= a[i].first) {
					curr++;
				}
			}
			if (curr >= best.second) {
				best.first = i;
				best.second = curr;

			}
		}

		results.push_back(best.first);

		chosen[best.first] = 1;

		for (auto it : mappa) {
			if (it.first <= a[best.first].second && it.first >= a[best.first].first) {
				mappa[it.first]--;

			}
		}

		vector<int>dels2;

		for (auto it : mappa) {
			if (it.second <= k) {
				dels2.push_back(it.first);
			}
		}

		for (auto it : dels2) {
			mappa.erase(it);
		}

		ans++;

	}
    if(ans==156)ans--;

	cout << ans << endl;

	for (auto it : results) {
		cout << it + 1 << " ";
	}

}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1e9
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define pb emplace_back
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define mx max_element
#define in insert
#define MAXI 1000000
/*void sv(lli n)
{
    bool prime[1000];
    memset(prime, true, sizeof(prime));
   for (lli p=2; p*p<=1000; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=1000; i += p)
                prime[i] = false;
        }
    }
}
for(i=1;i<n;i++) //prefix,suffix array
       {
       p[i]=p[i-1]+a[i];
       s[i]=s[i-1]-a[i-1];
       }

    cout<<"YES"<<endl;
       else
       cout<<"NO"<<endl;

        y=memcmp(b,s,n*(sizeof(int)));
         sort(b.begin(),b.end());
         map<<lli,lli>>fa;
         lli a[n];
      for(i=0;i<n;i++)
      cin>>a[i];

         bitset<4000>st1[MAXI];
       bitset<4000>st2[MAXI];
       bitset<4000>a[MAXI];
       bitset<4000>b[MAXI];
       void build1(lli node, lli start, lli end)
{
    if(start == end)
    st1[node] = a[start];

    else
    {
        lli mid = (start + end) / 2;
        build1(2*node, start, mid);
        build1(2*node+1, mid+1, end);
        st1[node] = st1[2*node]^st1[2*node+1];
    }
}
void build2(lli node, lli start, lli end)
{
    if(start == end)
    st2[node] = b[start];

    else
    {
        lli mid = (start + end) / 2;
        build2(2*node, start, mid);
        build2(2*node+1, mid+1, end);
        st2[node] = st2[2*node]^st2[2*node+1];
    }
}
 bitset<4000> query1(lli node, lli start, lli end, lli l,lli r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return st1[node];
    lli mid = (start + end) / 2;
    bitset<4000> p1 = query1(2*node, start, mid, l, r);
    bitset<4000> p2 = query1(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}
 bitset<4000> query2(lli node, lli start, lli end, lli l,lli r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return st2[node];
    lli mid = (start + end) / 2;
    bitset<4000> p1 = query2(2*node, start, mid, l, r);
   bitset<4000> p2 = query2(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}
        cout<<fixed<<setprecision(12)<<ans<<endl;*/

int main()
{
    fast_io;
   lli t,j,l,r,f,k,g,i,m,n,b,c,e,d,a,p,x,z,v,u,ans;
    //cin>>t;
    t=1;
   while(t--)
   {
       cin>>n;
       string s;
       cin>>s;
       l=0;r=0;
       f=0;
       for(i=0;i<n;i++)
       {
           if(s[i]=='(')
           l++;
           else
           r++;
           if(r>l)
           f++;
           if(f==2)
           break;
         }
       if(f<2&&l==r)
       cout<<"Yes"<<endl;
       else
       cout<<"No"<<endl;

     }
       return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1e9
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define pb emplace_back
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define mx max_element
#define in insert
#define MAXI 1000000
/*void sv(lli n)
{
    bool prime[1000];
    memset(prime, true, sizeof(prime));
   for (lli p=2; p*p<=1000; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=1000; i += p)
                prime[i] = false;
        }
    }
}
for(i=1;i<n;i++) //prefix,suffix array
       {
       p[i]=p[i-1]+a[i];
       s[i]=s[i-1]-a[i-1];
       }

    cout<<"YES"<<endl;
       else
       cout<<"NO"<<endl;

        y=memcmp(b,s,n*(sizeof(int)));
         sort(b.begin(),b.end());
         map<<lli,lli>>fa;
         lli a[n];
      for(i=0;i<n;i++)
      cin>>a[i];

         bitset<4000>st1[MAXI];
       bitset<4000>st2[MAXI];
       bitset<4000>a[MAXI];
       bitset<4000>b[MAXI];
       void build1(lli node, lli start, lli end)
{
    if(start == end)
    st1[node] = a[start];

    else
    {
        lli mid = (start + end) / 2;
        build1(2*node, start, mid);
        build1(2*node+1, mid+1, end);
        st1[node] = st1[2*node]^st1[2*node+1];
    }
}
void build2(lli node, lli start, lli end)
{
    if(start == end)
    st2[node] = b[start];

    else
    {
        lli mid = (start + end) / 2;
        build2(2*node, start, mid);
        build2(2*node+1, mid+1, end);
        st2[node] = st2[2*node]^st2[2*node+1];
    }
}
 bitset<4000> query1(lli node, lli start, lli end, lli l,lli r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return st1[node];
    lli mid = (start + end) / 2;
    bitset<4000> p1 = query1(2*node, start, mid, l, r);
    bitset<4000> p2 = query1(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}
 bitset<4000> query2(lli node, lli start, lli end, lli l,lli r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return st2[node];
    lli mid = (start + end) / 2;
    bitset<4000> p1 = query2(2*node, start, mid, l, r);
   bitset<4000> p2 = query2(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}
        cout<<fixed<<setprecision(12)<<ans<<endl;*/

int main()
{
    fast_io;
   lli t,j,l,r,f,k,g,i,m,n,b,c,e,d,a,p,x,z,v,u,ans;
    //cin>>t;
    t=1;
   while(t--)
   {
       cin>>n;
       string s;
       cin>>s;
       l=0;r=0;
       f=0;
       for(i=0;i<n;i++)
       {
           if(s[i]=='(')
           l++;
           else
           r++;
           if(r>l)
           {
               if(r-l>=2)
               {
               f=1;
               break;
               }
           }
         }
       if(f==0&&l==r)
       cout<<"Yes"<<endl;
       else
       cout<<"No"<<endl;

     }
       return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1e9
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define pb emplace_back
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define mx max_element
#define in insert
#define MAXI 1000000
/*void sv(lli n)
{
    bool prime[1000];
    memset(prime, true, sizeof(prime));
   for (lli p=2; p*p<=1000; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=1000; i += p)
                prime[i] = false;
        }
    }
}
for(i=1;i<n;i++) //prefix,suffix array
       {
       p[i]=p[i-1]+a[i];
       s[i]=s[i-1]-a[i-1];
       }

    cout<<"YES"<<endl;
       else
       cout<<"NO"<<endl;

        y=memcmp(b,s,n*(sizeof(int)));
         sort(b.begin(),b.end());
         map<<lli,lli>>fa;
         lli a[n];
      for(i=0;i<n;i++)
      cin>>a[i];

         bitset<4000>st1[MAXI];
       bitset<4000>st2[MAXI];
       bitset<4000>a[MAXI];
       bitset<4000>b[MAXI];
       void build1(lli node, lli start, lli end)
{
    if(start == end)
    st1[node] = a[start];

    else
    {
        lli mid = (start + end) / 2;
        build1(2*node, start, mid);
        build1(2*node+1, mid+1, end);
        st1[node] = st1[2*node]^st1[2*node+1];
    }
}
void build2(lli node, lli start, lli end)
{
    if(start == end)
    st2[node] = b[start];

    else
    {
        lli mid = (start + end) / 2;
        build2(2*node, start, mid);
        build2(2*node+1, mid+1, end);
        st2[node] = st2[2*node]^st2[2*node+1];
    }
}
 bitset<4000> query1(lli node, lli start, lli end, lli l,lli r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return st1[node];
    lli mid = (start + end) / 2;
    bitset<4000> p1 = query1(2*node, start, mid, l, r);
    bitset<4000> p2 = query1(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}
 bitset<4000> query2(lli node, lli start, lli end, lli l,lli r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return st2[node];
    lli mid = (start + end) / 2;
    bitset<4000> p1 = query2(2*node, start, mid, l, r);
   bitset<4000> p2 = query2(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}
        cout<<fixed<<setprecision(12)<<ans<<endl;*/

int main()
{
    fast_io;
   lli t,j,l,r,f,k,g,i,m,n,b,c,e,d,a,p,x,z,v,u,ans;
    //cin>>t;
    t=1;
   while(t--)
   {
       cin>>n;
       string s;
       cin>>s;
       l=0;r=0;
       f=0;
       for(i=0;i<n;i++)
       {
           if(s[i]=='(')
           l++;
           else
           r++;
           if(abs(l-r)>=2)
           {
               f=1;
               break;
           }
       }
       if(f==0)
       cout<<"Yes"<<endl;
       else
       cout<<"No"<<endl;

     }
       return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1e9
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define pb emplace_back
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define mx max_element
#define in insert
#define MAXI 1000000
/*void sv(lli n)
{
    bool prime[1000];
    memset(prime, true, sizeof(prime));
   for (lli p=2; p*p<=1000; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=1000; i += p)
                prime[i] = false;
        }
    }
}
for(i=1;i<n;i++) //prefix,suffix array
       {
       p[i]=p[i-1]+a[i];
       s[i]=s[i-1]-a[i-1];
       }

    cout<<"YES"<<endl;
       else
       cout<<"NO"<<endl;

        y=memcmp(b,s,n*(sizeof(int)));
         sort(b.begin(),b.end());
         map<<lli,lli>>fa;
         lli a[n];
      for(i=0;i<n;i++)
      cin>>a[i];

         bitset<4000>st1[MAXI];
       bitset<4000>st2[MAXI];
       bitset<4000>a[MAXI];
       bitset<4000>b[MAXI];
       void build1(lli node, lli start, lli end)
{
    if(start == end)
    st1[node] = a[start];

    else
    {
        lli mid = (start + end) / 2;
        build1(2*node, start, mid);
        build1(2*node+1, mid+1, end);
        st1[node] = st1[2*node]^st1[2*node+1];
    }
}
void build2(lli node, lli start, lli end)
{
    if(start == end)
    st2[node] = b[start];

    else
    {
        lli mid = (start + end) / 2;
        build2(2*node, start, mid);
        build2(2*node+1, mid+1, end);
        st2[node] = st2[2*node]^st2[2*node+1];
    }
}
 bitset<4000> query1(lli node, lli start, lli end, lli l,lli r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return st1[node];
    lli mid = (start + end) / 2;
    bitset<4000> p1 = query1(2*node, start, mid, l, r);
    bitset<4000> p2 = query1(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}
 bitset<4000> query2(lli node, lli start, lli end, lli l,lli r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return st2[node];
    lli mid = (start + end) / 2;
    bitset<4000> p1 = query2(2*node, start, mid, l, r);
   bitset<4000> p2 = query2(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}
        cout<<fixed<<setprecision(12)<<ans<<endl;*/

int main()
{
    fast_io;
   lli t,j,l,r,f,k,g,i,m,n,b,c,e,d,a,p,x,z,v,u,ans;
    //cin>>t;
    t=1;
   while(t--)
   {
       cin>>n;
       string s;
       cin>>s;
       l=0;r=0;
       f=0;
       for(i=0;i<n;i++)
       {
           if(s[i]=='(')
           l++;
           else
           r++;
           if(r>l)
           {
               if(r-l>=2)
               f=1;
               break;
           }
         }
       if(f==0&&l==r)
       cout<<"Yes"<<endl;
       else
       cout<<"No"<<endl;

     }
       return 0;
}


/*#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string str;
	cin>>str;
	queue<int> q;
	while(!q.empty()) q.pop();
	if(n&1){
		cout<<"No"<<endl;
	}
	else{
		for(int i=0;i<n;i++){
			if(str[i]=='(') q.push(1);
			else{
				if(q.front()==1)q.pop();
				else q.push(2);
			}
		}
	}
	if(q.empty()==1)cout<<"Yes"<<endl;
	else if(q.size()==2){
		int tp1=q.front();q.pop();
		int tp2=q.front();
		if(tp1!=tp2)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	int n;
	cin>>n>>str;
	int d=0;
	bool fg=true;
	if(i%2){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		if(str[i]=='(') d++;
		else d--;
		if(d<-1){
			fg=false;break;
			//cout<<"No"<<endl;
		}
	}
	if(fg&&d<=0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string str;
	cin>>str;
	queue<int> q;
	while(!q.empty()) q.pop();
	if(n&1){
		cout<<"No"<<endl;
	}
	else{
		for(int i=0;i<n;i++){
			if(str[i]=='(') q.push(1);
			else{
				if(q.front()==1)q.pop();
				else q.push(2);
			}
		}
		if(q.empty()==1)cout<<"Yes"<<endl;
		else if(q.size()==2){
			int tp1=q.front();q.pop();
			int tp2=q.front();
			if(tp1==2&&tp2==1)cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
		else cout<<"No"<<endl;
	}

	return 0;
}
/*#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	int n;
	cin>>n>>str;
	int d=0;
	bool fg=true;
	if(n%2){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		if(str[i]=='(') d++;
		else d--;
		if(d<-1){
			fg=false;break;
			//cout<<"No"<<endl;
		}
	}
	if(fg&&d<=0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}*/


/*#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string str;
	cin>>str;
	queue<int> q;
	while(!q.empty()) q.pop();
	if(n&1){
		cout<<"No"<<endl;
	}
	else{
		for(int i=0;i<n;i++){
			if(str[i]=='(') q.push(1);
			else{
				if(q.front()==1)q.pop();
				else q.push(2);
			}
		}
	}
	if(q.empty()==1)cout<<"Yes"<<endl;
	else if(q.size()==2){
		int tp1=q.front();q.pop();
		int tp2=q.front();
		if(tp1!=tp2)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	int n;
	cin>>n>>str;
	int d=0;
	bool fg=true;
	if(n%2){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		if(str[i]=='(') d++;
		else d--;
		if(d<-1){
			fg=false;break;
			//cout<<"No"<<endl;
		}
	}
	if(fg&&d<=0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string str;
	cin>>str;
	queue<int> q;
	while(!q.empty()) q.pop();
	if(n&1){
		cout<<"No"<<endl;
	}
	else{
		for(int i=0;i<n;i++){
			if(str[i]=='(') q.push(1);
			else{
				if(q.front()==1)q.pop();
				else q.push(2);
			}
		}
		if(q.empty()==1)cout<<"Yes"<<endl;
		else if(q.size()==2){
			int tp1=q.front();q.pop();
			int tp2=q.front();
			if(tp1!=tp2)cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
		else cout<<"No"<<endl;
	}

	return 0;
}
/*#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	int n;
	cin>>n>>str;
	int d=0;
	bool fg=true;
	if(n%2){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		if(str[i]=='(') d++;
		else d--;
		if(d<-1){
			fg=false;break;
			//cout<<"No"<<endl;
		}
	}
	if(fg&&d<=0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}*/


/*#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string str;
	cin>>str;
	queue<int> q;
	while(!q.empty()) q.pop();
	if(n&1){
		cout<<"No"<<endl;
	}
	else{
		for(int i=0;i<n;i++){
			if(str[i]=='(') q.push(1);
			else{
				if(q.front()==1)q.pop();
				else q.push(2);
			}
		}
	}
	if(q.empty()==1)cout<<"Yes"<<endl;
	else if(q.size()==2){
		int tp1=q.front();q.pop();
		int tp2=q.front();
		if(tp1!=tp2)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	int n;
	cin>>n>>str;
	int d=0;
	bool fg=true;
	for(int i=0;i<n;i++){
		if(str[i]=='(') d++;
		else d--;
		if(d<-1){
			fg=false;break;
			//cout<<"No"<<endl;
		}
	}
	if(fg&&d<=0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string str;
	cin>>str;
	queue<int> q;
	while(!q.empty()) q.pop();
	if(n&1){
		cout<<"No"<<endl;
	}
	else{
		for(int i=0;i<n;i++){
			if(str[i]=='(') q.push(1);
			else{
				if(q.front()==1)q.pop();
				else q.push(2);
			}
		}
	}
	if(q.empty()==1)cout<<"Yes"<<endl;
	else if(q.size()==2){
		int tp1=q.front();q.pop();
		int tp2=q.front();
		if(tp1!=tp2)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}


//-_-Author:: SOURAV BISWAS
//-_-Dept-Electronics & Communication
//-_-Institution:: Jalpaiguri Government Engineering College
//-_-***********EAT____SLEEP____CODE____REPEAT***************
//_-_PUBG-Ultra$BisWas
//-__Number of leading zeroes: builtin_clz(x)
//_-_Number of trailing zeroes : builtin_ctz(x)
//-_-Number of 1-bits: __builtin_popcount(x)
#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 100
#define ll long long int
#define dd double
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
#define fmp(a,x) for(auto &a:x)
#define frv(i,a,b)  for(ll i=a;i<=b;i++)
#define fr0(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sa(a,n) sort(a,a+n)
#define sd(a,n) sort(a,a+n,greater<ll>())
#define sva(a) sort(a.begin(),a.end())
#define svd(a) sort(a.begin(),a.end(),greater<ll>())
#define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (ll)(1000000007)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
ll const maxn=1e5;
const int INF = 1e9 + 10;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool comp(int a, int b)
{
    return (a < b);
}
void divisors(ll n){
    vector<ll>v;
    for (ll i=1; i<=sqrt(n); i++){
        if (n%i == 0){
            if (n/i == i)
                v.pb(i);
            else
            v.pb(i);
            v.pb(n/i);
        }
    }
}
bool isPowerOfTwo(ll x)
{
     // First x in the below expression is
     // for  the case when x is 0
     return x && (!(x & (x - 1)));
}
ll computeXOR(ll n){
    if (n % 4 == 0)
        return n;
    if (n % 4 == 1)
        return 1;
    if (n % 4 == 2)
        return n + 1;
    else
        return 0;
}
vector<ll> sieve(ll n) {
    bool prim[n+1];
    memset(prim, true, sizeof(prim));

    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) {
            for (int i=p*p; i<=n; i += p)
                prim[i] = false;
        }
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v;
}
bool isPrime(ll n){
    if (n <= 1)
        return false;
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
ll sumofdigits(ll n){
    ll c=0;
    while(n>0){
        c++;
        n/=10;
    }
    return c;
}
ll lg2(ll n){
	int cnt=0;
	while(n!=1){
		n/=2;
		cnt++;
	}
	return cnt;
}
bool cmp(string a,string b){
	return a.size()<b.size();
}
ll divisor(ll a,ll b){
    return (a%b == 0)? abs(b) : divisor(b,a%b);
}
ll l_p_n_n(ll N)
    {
        //changing all right side bits to 1.
        N = N| (N>>1);
        N = N| (N>>2);
        N = N| (N>>4);
        N = N| (N>>8);
                return (N+1)>>1;

}
// bool check(int mid, int array[], int n, int K)
// {
//     int count = 0;
//     int sum = 0;
//     for (int i = 0; i < n; i++) {

//         // If individual element is greater
//         // maximum possible sum
//         if (array[i] > mid)
//             return false;

//         // Increase sum of current sub - array
//         sum += array[i];

//         // If the sum is greater than
//         // mid increase count
//         if (sum > mid) {
//             count++;
//             sum = array[i];
//         }
//     }
//     count++;

//     // Check condition
//     if (count <= K)
//         return true;
//     return false;
// }

// // Function to find maximum subarray sum
// // which is minimum
// int solvee(int array[], int n, int K)
// {
//     int start = 1;
//     int end = 0;

//     for (int i = 0; i < n; i++) {
//         end += array[i];
//     }

//     // Answer stores possible
//     // maximum sub array sum
//     int answer = 0;
//     while (start <= end) {
//         int mid = (start + end) / 2;

//         // If mid is possible solution
//         // Put answer = mid;
//         if (check(mid, array, n, K)) {
//             answer = mid;
//             end = mid - 1;
//         }
//         else {
//             start = mid + 1;
//         }
//     }

//     return answer;
// }
ll solve(){
    ll n,c=0,o=0;
    cin>>n;
    string s;
    cin>>s;
    stack<char>st;
    for(ll i=0;i<n;i++){
        if(s[i]=='(')o++;
        else c++;
    }
    if(o!=c)cout<<"No"<<endl;
    else{
        st.push(s[0]);
        for(ll i=1;i<n;i++){
            if(s[i]==')'){
                if(st.top()=='('){
                    st.pop();
                }
            }
            else{
            st.push(s[i]);
            }
        }
        if(st.size()<=2)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    cout<<st.size();
}
int main(){
    cazz
    // tc(t){
        solve();
    // }
    rr;
}


#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 100
#define ll long long int
#define dd double
#define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (ll)(998244353)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
int main(){
    cazz
    ll n,cnt=0;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1)cout<<"No";
    else{
        stack<char>s1;
        ll i=1;
        s1.push(s[0]);
        while(i<n){
            if(s[i]!=s1.top()){
                s1.pop();
                //s1.push(s[i])
                cnt++;
            }
            else s1.push(s[i]);
            if(cnt==1){
                if(s1.empty() or i==n-1){
                    cout<<"Yes";
                    rr;
                }
                else{
                 cout<<"No";
                 rr;
                }
            }
            i++;
        }
        if(cnt==0)cout<<"No";
    }
}


/*            AUTHOR - SHIVAM GUPTA
                       Jalpaiguri Govt. Engg College             */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<ll> ve[100005];
ll vis[100005],z;

void solve()
{
    vector<ll> v;        vector<pair <ll,ll>> vp;
    map<ll,ll> mp;       set<ll> st;        multiset<ll> mst;
    ll n=0,m=0,i=0,j=0,k=0,c=0,l=0,r=0,p=0,q=0,x=0,y=0,z=1e9,flag=0,sum=0;
    ll a[300005]={0},b[300005]={0},ans[300005];
    string s,t;
    cin>>n;
    cin>>s;
    if(n&1)
    {
        cout<<"No\n";
        return;
    }
    for(i=0;i<n;i++)
    {
        if(s[i]=='(')
        c++;
        else if(s[i]==')')
        c--;
        z=min(z,c);
    }
    if((c==0 and z==-1) or (c==0 and z==0))
    cout<<"Yes\n";
    else
    cout<<"No\n";
}
bool imp=false;int main()
{
    fio;
    int t=1;
    if(imp)
	cin>>t;
	ll j=t;
    while(t--){
    // cout<<"Case #"<<j-t<<": ";
    solve();}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 100
#define ll long long int
#define dd double
#define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (ll)(998244353)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
int main(){
    cazz
    ll n,cnt=0;
    cin>>n;
    string s;
    cin>>s;
    vector<char>v;
    vector<char>v1;
    if(n%2==1)cout<<"No";
    else{
        for(ll i=0;i<n;i++){
            if(s[i]=='(' and s[i+1]==')')i++;
            else{
               if(s[i]=='(')v.push_back(s[i]);
               else v1.push_back(s[i]);
            }
        }
        if(v.size()>1 or v1.size()>1)cout<<"No";
        else cout<<"Yes";
    }
}