#include <bits/stdc++.h>
using namespace std;
long long POWER(long long a, long long p) {
  if (p == 0) return 1;
  long long b = a;
  for (int i = 1; i < p; i++) {
    b *= a;
  }
  return b;
}
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    int r, t;
    cin >> r >> t;
    if (r > t) swap(r, t);
    a[i] = r;
    b[i] = t;
  }
  if (a.size() == 1) {
    int c = 0;
    if (x > b[0])
      c = abs(x - b[0]);
    else if (x < a[0])
      c = abs(x - a[0]);
    cout << c;
    return 0;
  }
  bool k = 1;
  int p = -1;
  for (int i = 0; i <= 1000; i++) {
    bool d = 1;
    for (int j = 0; j < a.size(); j++) {
      if (!(i >= a[j] && i <= b[j])) {
        d = 0;
        break;
      }
    }
    if (d) {
      if (k) {
        k = 0;
        p = i;
      } else {
        if (abs(i - x) < abs(x - p)) p = i;
      }
    }
  }
  if (p == -1)
    cout << -1;
  else {
    int u = abs(x - p);
    cout << u;
  }
  return 0;
}
