#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
long long mod = 1000000007;
long long kmp(string x) {
  long long n = x.length();
  vector<long long> lcp(x.length(), 0);
  for (long long i = 1; i < n; i++) {
    long long j = lcp[i - 1];
    while (j > 0 && x[j] != x[i]) j = lcp[j - 1];
    if (x[i] == x[j]) j++;
    lcp[i] = j;
  }
  return lcp[n - 1];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    long long l = 0, r = INT_MAX;
    for (long long i = 0; i < n; i++) {
      long long a, b;
      cin >> a >> b;
      if (a > b) swap(a, b);
      l = max(l, a);
      r = min(r, b);
    }
    if (l > r) {
      cout << -1;
      return 0;
    }
    if (x < l)
      cout << l - x;
    else if (x > r)
      cout << x - r;
    else
      cout << 0;
  }
  return 0;
}
