#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, i, a, b, m, M;
  cin >> n >> x;
  vector<pair<int, int> > vec;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    if (a > b) swap(a, b);
    vec.push_back({a, b});
  }
  m = vec[0].first;
  M = vec[0].second;
  for (auto i : vec) {
    m = max(m, i.first);
    M = min(M, i.second);
  }
  if (m > M)
    cout << "-1" << endl;
  else {
    if (x >= m && x <= M)
      cout << "0" << endl;
    else if (x < m)
      cout << m - x << endl;
    else
      cout << x - M << endl;
  }
}
