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