#include <bits/stdc++.h>
using namespace std;
void inout() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void SieveOfEratosthenes(long long n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p]) {
      for (long long i = p * p; i <= n; i += p) {
        prime[i] = false;
      }
    }
  }
  for (long long i = 2; i <= n; i++) {
    if (prime[i]) {
      cout << i << " ";
    }
  }
}
void printDivisors(long long n) {
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        printf("%d ", i);
      else
        printf("%d %d ", i, n / i);
    }
  }
}
void solve() {
  long long n, k;
  cin >> n;
  cin >> k;
  long long x, y, a, b, maxi, mini;
  mini = 10000;
  maxi = 0;
  for (long long i = 0; i < n; i++) {
    cin >> x >> y;
    a = (((x) < (y)) ? (x) : (y));
    b = (((x) > (y)) ? (x) : (y));
    if (b < mini) {
      mini = b;
    }
    if (a > maxi) {
      maxi = a;
    }
  }
  if (maxi <= mini) {
    if (k >= maxi && k <= mini) {
      cout << 0;
    } else if (k <= mini && k <= maxi) {
      cout << maxi - k;
    } else {
      cout << k - mini;
    }
  } else {
    cout << -1;
  }
}
int32_t main() {
  inout();
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
