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