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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// includes and namespaces

#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;

#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'

using ll = long long;
using ull = unsigned long long;
using db = double;  // or double, if TL is tight
using str = string;      // yay python!

// pairs

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define mp make_pair
#define f first
#define s second

// template classes

#define tcT template <class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT > using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;

// vector defines

using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
using vpd = V<pd>;

// more vector defines

#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()

// binsearch

#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define rep(a) F0R(_, a)
#define each(a, x) for (auto &a : x)



// const values

const int MOD = 1e9+7;
const int MX = (int)2e5 + 5;
const ll BIG = 1e18;  // not too close to LLONG_MAX

// fast power

long long FastPow(long long a, long long b)
{
    if(b==0) {return 1;}
    if(b==1) {return a;}
    if(b==2) {return a*a%MOD;}
    if(b%2==0) return FastPow(FastPow(a,b/2), 2);
    return FastPow(FastPow(a, b/2), 2)*a%MOD;
}

// code
//never back down never WHAT!
//NEVER GIVE UP

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, s, l, p;
    cin >> n >> m >> s;
    ll wyn = BIG;
    int ind;
    for (int i = 0; i<m; i++)
    {
        cin >> l >> p;
        if (l>s and p>s)
        {
            if (l-1-s<wyn)
            {
                wyn = l-1-s;
                ind = l-1;
            }
            if (l-1-s==wyn and l-1<ind)
            {
                wyn = l-1-s;
                ind = l-1;
            }
        }
        if (l<s and p<s)
        {
            if (s-p-1<wyn)
            {
                wyn = s-p-1;
                ind = p+1;
            }
            if (s-p-1==wyn and p+1<ind)
            {
                wyn = s-p-1;
                ind = p+1;
            }
        }
        if (l<=s and p>=s)
        {
            if (p+1-s<wyn)
            {
                wyn = p+1-s;
                ind = p+1;
            }
            if (p+1-s==wyn and p+1<ind)
            {
                wyn = p+1-s;
                ind = p+1;
            }
            if (s-l+1<wyn)
            {
                wyn = s-l+1;
                ind = l-1; 
            }
            if (s-l+1==wyn and l-1<ind)
            {
                wyn = s-l+1;
                ind = l-1; 
            }
        }
    }
    cout << ind;
}