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