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