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