#include <bits/stdc++.h>
using namespace std;
const int maxn = 1024;
int color[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x0, fi, la;
  cin >> n >> x0;
  for (int j = 0; j != n; ++j) {
    cin >> fi >> la;
    int minn = min(fi, la);
    int maxx = max(fi, la);
    for (int i = minn; i <= maxx; ++i) ++color[i];
  }
  int differ = (0x3f3f3f3f);
  for (int i = 0; i != maxn; ++i)
    if (color[i] == n) differ = min(differ, abs(i - x0));
  if (differ == (0x3f3f3f3f))
    cout << -1 << '\n';
  else
    cout << differ << '\n';
  return 0;
}
