#include <bits/stdc++.h>
using namespace std;
int x[1001];
void print() {
  cout << "\n";
  for (int i = 0; i < 1001; i++) {
    cout << x[i] << ",";
  }
  cout << endl;
}
int main() {
  for (int i = 0; i < 1001; i++) x[i] = 0;
  int n, x0;
  cin >> n >> x0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b) {
      int temp = a;
      a = b;
      b = temp;
    }
    for (int j = a; j <= b; j++) x[j]++;
  }
  int s = -1, e = -1;
  for (int i = 0; i < 1001; i++) {
    if (x[i] == n) {
      s = i;
      break;
    }
  }
  if (s == -1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = s; i < 1001; i++) {
    if (x[i] == n) {
      e = i;
    } else {
      break;
    }
  }
  if (x0 >= s && x0 <= e)
    cout << "0\n";
  else if (x0 < s) {
    cout << s - x0 << endl;
  } else if (x0 > e) {
    cout << x0 - e << endl;
  }
  return 0;
}
