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