#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 1 << "\n";
    return 0;
  }
  if (m * 2 <= n) {
    cout << m << "\n";
  } else {
    cout << n - m << "\n";
  }
  return 0;
}
