#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  vector<pair<int, int> > players;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    players.push_back(make_pair(a, b));
  }
  int ans = INT_MAX;
  for (int pos = 0; pos <= 1000; pos++) {
    int cnt = 0;
    for (int it = 0; it < n; it++) {
      pair<int, int> player = players[it];
      if (pos >= player.first and pos <= player.second) {
        cnt++;
      }
    }
    if (cnt == n) {
      ans = min(ans, (int)fabs(pos - x));
    }
  }
  if (ans == INT_MAX) {
    cout << "-1\n";
  } else {
    cout << ans << endl;
  }
  return 0;
}
