#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m = -1, M = 1001, x;
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l > r) swap(l, r);
    m = max(m, l);
    M = min(M, r);
  }
  if (m > M)
    printf("-1\n");
  else if (x < m)
    printf("%d\n", m - x);
  else if (x > M)
    printf("%d\n", x - M);
  else
    printf("0\n");
  return 0;
}
