#include <bits/stdc++.h>
using namespace std;
void origi() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
}
void tiranga() {
  int n, a;
  vector<int> r;
  vector<int> l;
  cin >> n >> a;
  for (int i = 0; (int)i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    r.push_back(y);
    l.push_back(x);
  }
  int right = *min_element(r.begin(), r.end());
  int left = *max_element(l.begin(), l.end());
  if (right < left)
    cout << -1;
  else {
    if (a >= left && a <= right)
      cout << 0;
    else if (a < left)
      cout << left - a;
    else
      cout << a - right;
  }
}
int main() {
  origi();
  tiranga();
}
