#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, x, a, b, t, p, q;
  cin >> n >> x;
  p = -1;
  q = 10000;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    if (a > b) {
      t = a;
      a = b;
      b = t;
    }
    if (a > p) p = a;
    if (b < q) q = b;
  }
  if (p > q)
    cout << -1;
  else {
    if (x >= p && x <= q)
      cout << 0;
    else if (x < p)
      cout << p - x;
    else
      cout << x - q;
  }
  return 0;
}
