#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  fast();
  long long int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, t, type, sum1 = 0,
                sum2 = 0, sum = 0, flag = 0, mini = 0, pos = 0, add = 0,
                count = 0, a1 = 0, b1 = 0, c1 = 0, end = 0, index = 0;
  long long int n, m, h, i, j, g, p, q, r, l, u, v, k, x, y, z, x1, x2, y1, y2,
      gcdc, centre = 0, maxi = 0, med = 0, start = 0, ans = 0, mid = 0, lo = 0,
            hi = 0, rem = 0, one;
  string s, s1, s2, s3, s4, s5, s6, s7, s8, s9;
  {
    cin >> n >> x;
    c = INT_MIN;
    d = INT_MAX;
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      c = max(c, min(a, b));
      d = min(d, max(a, b));
    }
    if (c > d)
      cout << "-1";
    else {
      if (x >= c && x <= d)
        cout << "0";
      else
        cout << min(abs(x - c), abs(x - d));
    }
  }
  return 0;
}
