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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include<vector>
using namespace std;

int searchBuild(vector<bool> vec, int s)
{
  int a=s-1,b=s-1;
  while(true)
  {
    if(a!=0)
    {
      a--;
    }
    if(b!=vec.size()-1)
    {
      b++;
    }
    if(vec[a]==false)
    {
      return a;
    }
    if(vec[b]==false)
    {
      return b;
    }
  }
}


int main() 
{
  int n,m,s;
  cin>>n>>m>>s;
  vector<bool> build;
  for(int i=0;i<n;i++)
  {
    build.push_back(false);
  }
  for(int i=0;i<m;i++)
  {
    int l,r;
    cin>>l>>r;
    for(int j=l;j<=r;j++)
    {
      build[j-1]=true;
    }
  }
    cout<<searchBuild(build,s)+1;
    return 0;
}