#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  bool check1 = 1, check2 = 1;
  cin >> n >> x;
  vector<pair<int, int> > arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
    if (arr[i].first > arr[i].second) {
      int temp = arr[i].first;
      arr[i].first = arr[i].second;
      arr[i].second = temp;
    }
  }
  sort(arr.begin(), arr.end());
  int x0 = x;
  for (int i = 0; i < n; ++i) {
    check1 = true, check2 = true;
    if (arr[i].first > x || arr[i].second < x) {
      for (int j = 0; j < i; j++) {
        if (arr[j].first > arr[i].first || arr[j].second < arr[i].first) {
          check1 = 0;
        }
        if (arr[j].first > arr[i].second || arr[j].second < arr[i].second) {
          check2 = 0;
        }
      }
      if (check1 && !check2)
        x = arr[i].first;
      else if (check2 && !check1)
        x = arr[i].second;
      else if (check1 && check2) {
        if (max(x0, arr[i].first) - min(x0, arr[i].first) >
            max(x0, arr[i].second) - min(x0, arr[i].second))
          x = arr[i].second;
        else
          x = arr[i].first;
      } else if (!check1 && !check2) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << max(x, x0) - min(x, x0);
}
