func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;   const long long LINF = 1e18;   long long int n, cnt = 0, ans = 0, a, b, c, d, cmp[ohara], cmpp, m, h, w, x, y,                    sum[ohara], pos;   int dy[] = {1, 0, -1, 0};   int dx[] = {0, 1, 0, -1};   string alph( abcdefghijklmnopqrstuvwxyz ), s;   bool fl = true;   struct edge {     int to, cost;   };   int main(void) {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> n >> c;     for (long long int(i) = 0; (i) < (int)(n); (i)++) {       cin >> a >> b;       if (a > b) {         pos = b;         b = a;         a = pos;       }       sum[a]++;       sum[b + 1]--;     }     for (long long int i = (1); i < (9999); i++) {       sum[i] += sum[i - 1];     }     for (long long int(i) = 0; (i) < (int)(9999); (i)++) {       if (sum[i] == n) {         cmp[cnt] = i;         cnt++;         fl = false;       }     }     if (fl) {       cout << (-1) << endl;       return 0;     }     ans = INF;     for (long long int(i) = 0; (i) < (int)(cnt); (i)++) {       ans = min(ans, max(cmp[i], c) - min(cmp[i], c));     }     cout << (ans) << endl;     return 0;   }   