#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long a, b;
  cin >> a >> b;
  if (b == 0)
    cout << 1;
  else if (b >= double(a / 2.0))
    cout << a - b;
  else {
    cout << b;
  }
  return 0;
}
