#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x0, left = INT_MIN, right = INT_MAX;
  cin >> n >> x0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    left = max(left, min(a, b));
    right = min(right, max(a, b));
  }
  if (left > right)
    cout << "-1" << endl;
  else if (x0 < left)
    cout << left - x0 << endl;
  else if (x0 > right)
    cout << x0 - right << endl;
  else
    cout << 0 << endl;
  return 0;
}
