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