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