#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (m == 0) return cout << 1 << '\n', 0;
  if (n % 2 == 1) {
    if (m <= n / 2)
      cout << m << '\n';
    else if (m == n / 2 + 1)
      cout << m - 1 << '\n';
    else
      cout << n - m << '\n';
  } else {
    if (m <= n / 2)
      cout << m << '\n';
    else
      cout << n - m << '\n';
  }
}
