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