1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <bits/stdc++.h>
using namespace std;
long long n,s,h,d,k;
int m;
vector<bool>v(1000000000);
int main(){
	cin>>n>>m>>s;
	v[s-1]=1;
	for(int i=0; i<m; i++){
        cin>>h>>d;
        //cout<<"1"<<endl;
        for(int j=h-1; j<d; j++){
            v[j]=1;
            //cout<<"2"<<endl;
        }
	}
	while(0==0){
	//cout<<"3"<<endl;
        if((s-k-1)>=0 && v[s-k-1]==0){
            cout<<s-k;
            return 0;
        }
        else if(v[s+k-1]==0){
            cout<<s+k;
            return 0;
        }
        k++;
	}
}