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