This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, m, x[N], y[N];
signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  int ans = m;
  for (int i = 0; i < n; i++) {
    if (x[i]%2) {
      ans = min(ans, x[i]-1);
    }
    else if (y[i]%2) {
      ans = min(ans, x[i]);
    }
  }
  cout << ans << "\n";
}
/*
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int N = 2e5+5, inf = INT_MAX;
int n, m, x[N], y[N];
pair<int, int> s;
vector<pair<int, int>> odd, even;
set<pair<int, int>>  odd2, even2;
signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin >> n >> m; 
  if (m&1) m--;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i]; 
    if (x[i]&1) m = min(m, x[i]-1);
  }
  for (int i = 0; i < n; i++) {
    x[i] = min(x[i], m);
  }
  for (int i = 0; i < n; i++) {
    if (y[i] != y[(i+1)%n]) continue;
    if (y[i]&1) odd.push_back(make_pair(min(x[i], x[(i+1)%n]), -max(x[i], x[(i+1)%n])));
    else even.push_back(make_pair(min(x[i], x[(i+1)%n]), -max(x[i], x[(i+1)%n])));
  }
  sort(all(odd));
  sort(all(even));
  int R = -1;
  for (int i = 0; i < odd.size(); i++) {
    odd[i].second = -odd[i].second;
    if (odd[i].second > R) {
      odd2.insert(odd[i]);
      R = odd[i].second;
    }
  }
  
  R = -1;
  for (int i = 0; i < even.size(); i++) {
    even[i].second = -even[i].second;
    if (even[i].second > R) {
      even2.insert(even[i]);
      R = even[i].second;
    }
  }
  for (int i = 0; i < n; i++) {
    s[i] = make_pair(y[i], i);
  }
  sort(s, s+n);
  int ans = m;
  for (int ii = 0; ii < n; ii++) {
    int i = s[i].second;
    
    if (y[i]&1) {
      // miro los even
      auto it = even2.upper_bound(make_pair(x[i]+1, x[i]+1));
      if (it == even2.begin()) continue;
      it = prev(it);
      if (it->second >= x[i]) ans = min(ans, x[i]);
    }
    else {
      // miro los odds
      auto it = upper_bound(all(odd2), make_pair(x[i]+1, x[i]+1));
      if (it == odd2.begin()) continue;
      it = prev(it);
      if (it->second >= x[i]) ans = min(ans, x[i]);
    }
  }
  if (ans&1) ans--;
  cout << ans << "\n";
}
/*
  cin >> n >> m;
  for (int i = 0; i <= m; i++) {
    mx[i] = -inf;
    mn[i] = inf;
  }
  bool ok = 1;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    if (x[i]%2) m = x[i]-1;
    mx[x[i]] = max(mx[x[i]], y[i]);
    mn[x[i]] = min(mn[x[i]], y[i]);
  
    if (0 < i < n-1 && (x[i] < x[i-1] || y[i] > y[i-1])) ok = 0;
  }
  if (max(x[n-1], y[n-1])) ok = 0;
  if (ok) {
    int ans = m;
    for (int i = 0; i < n; i++) {
      if (y[i]%2) {
        ans = x[i];
        break;
      }
      else if (i && (x[i]-x[i-1])%2) {
        ans = x[i]-1;
        break;
      }
    }
    cout << ans << "\n";
    return 0;
  }
  int ans = 0;
  for (int i = 0; i <= m; i+=2) {
    bool ok = 1;
    for (int j = 0; j <= 1000; j++) {
      // si en x = ans+1 hay un punto > j y otro <= j no se puede
      // si en
      if (mx[ans+1] > j && mn[ans+1] <= j) {
        ok = 0;
        break;
      }
    }
    if (!ok) break;
    ans += 2;
  }
  cout << ans << "\n";
  */
Compilation message (stderr)
Main.cpp:115:1: warning: "/*" within comment [-Wcomment]
  115 | /*
      || # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |