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