#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int main() {
  int n, x, i, j, left = 0, right = 99999, t = 0, k;
  cin >> n >> x;
  for (k = 0; k < n; k++) {
    cin >> i >> j;
    if (i > j) swap(i, j);
    left = max(left, i);
    right = min(right, j);
    if (left > right) t = 1;
  }
  if (t == 1)
    cout << "-1" << endl;
  else if (x >= left && x <= right)
    cout << "0" << endl;
  else
    cout << min(abs(left - x), abs(right - x));
  return 0;
}
