#include <bits/stdc++.h>
using namespace std;
typedef struct da {
  int s, e;
  int l;
} date;
date a[222];
int x0;
int n;
int main() {
  int a, b;
  int t1, t2, I;
  while (cin >> n >> x0) {
    t1 = -9999999;
    t2 = -t1;
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      if (a > b) swap(a, b);
      if (a > t1) t1 = a;
      if (b < t2) t2 = b;
    }
    if (t1 > t2)
      cout << -1 << endl;
    else {
      if (x0 < t1) cout << t1 - x0 << endl;
      if (x0 >= t1 && x0 <= t2) cout << 0 << endl;
      if (x0 > t2) cout << x0 - t2 << endl;
    }
  }
  return 0;
}
