#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0 || m == 1) {
    cout << 1 << endl;
    return 0;
  }
  n--;
  m--;
  int middle_remove = (n - 1) / 2;
  if (m <= middle_remove) {
    cout << m + 1 << endl;
  } else {
    int left = middle_remove + 1;
    if (n % 2 == 0) m--;
    std::cout << left - m + middle_remove << endl;
  }
}
