#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, xo;
  long a[200], b[200], temp, kq, vt;
  cin >> n >> xo;
  for (long i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > b[i]) {
      temp = a[i];
      a[i] = b[i];
      b[i] = temp;
    }
  }
  bool ok;
  kq = -1;
  for (long i = 0; i <= 1000; i++) {
    vt = xo + i;
    ok = true;
    for (long j = 1; j <= n; j++)
      if (a[j] <= vt && vt <= b[j])
        ;
      else {
        ok = false;
        break;
      }
    if (ok) {
      kq = i;
      break;
    }
    vt = xo - i;
    ok = true;
    for (long j = 1; j <= n; j++)
      if (a[j] <= vt && vt <= b[j])
        ;
      else {
        ok = false;
        break;
      }
    if (ok) {
      kq = i;
      break;
    }
  }
  cout << kq;
  return 0;
}
