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