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