#include <bits/stdc++.h>
int n, x, i, t, tt, ttt, tttt, l = -2000, r = 2000;
int main(void) {
  scanf("%d %d", &n, &x);
  for (i = 0; i < n; ++i) {
    scanf("%d %d", &t, &tt);
    ttt = (t > tt) ? tt : t;
    tttt = (t > tt) ? t : tt;
    t = (l > ttt) ? l : ttt;
    tt = (r > tttt) ? tttt : r;
    if (!((t <= tt) && (l <= t && tt <= r) && (ttt <= t && tt <= tttt))) {
      printf("-1");
      return 0;
    }
    l = t, r = tt;
  }
  if (l <= x && x <= r) {
    printf("0");
    return 0;
  }
  t = (l - x > 0) ? (l - x) : (x - l);
  tt = (r - x > 0) ? (r - x) : (x - r);
  ttt = (t > tt) ? (tt) : (t);
  printf("%d", ttt);
  return 0;
}
