#include <bits/stdc++.h>
using namespace std;
int n, x0;
struct node {
  int a, b;
} s[110];
int cmp(node l1, node l2) { return l1.a < l2.a; }
int main() {
  int u, v, i;
  while (cin >> n >> x0) {
    for (i = 0; i < n; i++) {
      cin >> u >> v;
      if (u > v) swap(u, v);
      s[i].a = u;
      s[i].b = v;
    }
    sort(s, s + n, cmp);
    int maxn = s[0].b;
    int minn = s[0].a;
    for (i = 1; i < n; i++) {
      if (s[i].b < minn) break;
      if (s[i].a > maxn) break;
      if (s[i].a > minn) minn = s[i].a;
      if (s[i].b < maxn) maxn = s[i].b;
    }
    if (i == n) {
      if (x0 >= minn && x0 <= maxn)
        cout << 0 << endl;
      else
        cout << min(abs(minn - x0), abs(maxn - x0)) << endl;
    } else
      cout << -1 << endl;
  }
  return 0;
}
