#include <bits/stdc++.h>
using namespace std;
bool isContains(int n, int m, int v) { return n <= v && v <= m; }
int solve() {
  int n, x0;
  int a, b;
  cin >> n >> x0;
  int mina = -1, maxb = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (a > b) swap(a, b);
    if (isContains(mina, maxb, a) || isContains(mina, maxb, b) ||
        isContains(a, b, mina) || isContains(a, b, maxb)) {
      mina = max(mina, a);
      maxb = min(maxb, b);
    } else {
      return -1;
    }
  }
  if (isContains(mina, maxb, x0)) {
    return 0;
  } else {
    return min(abs(double(x0 - mina)), abs(double(x0 - maxb)));
  }
}
int main() {
  cout << solve() << endl;
  return 0;
}
