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