#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, a, b, in[100], on[100], i = 0, r, y;
  cin >> n >> x;
  int t = n;
  while (t--) {
    cin >> a >> b;
    r = min(a, b);
    y = max(a, b);
    in[i] = r;
    on[i] = y;
    i++;
  }
  sort(in, in + n);
  sort(on, on + n);
  if (in[n - 1] < on[0]) {
    if (x <= in[n - 1])
      cout << in[n - 1] - x;
    else if (x >= on[0])
      cout << x - on[0];
    else if (x > in[n - 1] && x < on[0])
      cout << 0;
  } else if (in[n - 1] == on[0])
    cout << abs(x - on[0]);
  else
    cout << -1;
}
