#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int n, x0;
  int *a = new int[101];
  int *b = new int[101];
  cin >> n >> x0;
  int mn = INT_MAX;
  int mx = INT_MIN;
  for (int i = 0; i < n; i++) {
    int o, d;
    cin >> o >> d;
    a[i] = min(o, d);
    b[i] = max(o, d);
    mx = max(mx, a[i]);
    mn = min(mn, b[i]);
  }
  if (mx > mn) return cout << -1, 0;
  if (x0 >= mx && x0 <= mn)
    cout << 0;
  else if (x0 < mx)
    cout << (abs(x0 - mx));
  else
    cout << (abs(x0 - mn));
  return 0;
}
