#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x0;
  scanf("%d %d", &n, &x0);
  int a[100], b[100];
  int ans = 5000;
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &a[i], &b[i]);
    if (a[i] > b[i]) swap(a[i], b[i]);
  }
  for (int i = 0; i <= 1000; ++i) {
    bool ok = true;
    for (int j = 0; j < n; ++j)
      if (i < a[j] || i > b[j]) ok = false;
    if (ok) ans = min(ans, abs(x0 - i));
  }
  printf("%d\n", ans == 5000 ? -1 : ans);
}
int main() {
  solve();
  return 0;
}
