#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x0;
  cin >> n >> x0;
  int p1 = INT_MAX;
  int p2 = INT_MIN;
  int i;
  for (i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    if (b < a) swap(a, b);
    p1 = min(p1, b);
    p2 = max(p2, a);
  }
  if (p1 < p2) {
    cout << "-1" << endl;
    return 0;
  }
  if (p1 >= x0 && x0 >= p2) {
    cout << "0" << endl;
    return 0;
  }
  cout << min(abs(x0 - p1), abs(x0 - p2)) << endl;
}
