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