#include <bits/stdc++.h>
using namespace std;
string postFile = "test.txt";
void init() {}
void solve() {
  int n, x0;
  vector<pair<int, int> > a;
  cin >> n >> x0;
  for (int _n(n), i(0); i < _n; i++) {
    int ai, bi;
    cin >> ai >> bi;
    if (ai < bi)
      a.push_back(make_pair(ai, bi));
    else
      a.push_back(make_pair(bi, ai));
  }
  bool exist = false;
  int res = 1000000000;
  for (int _n(1001), i(0); i < _n; i++) {
    bool ok = true;
    for (int _n(a.size()), j(0); j < _n; j++) {
      if (!(a[j].first <= i && i <= a[j].second)) {
        ok = false;
        break;
      }
    }
    if (ok) {
      exist = true;
      res = min(res, abs(x0 - i));
    }
  }
  cout << (exist ? res : -1) << endl;
}
int main() {
  init();
  solve();
}
