#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int d = ceil(n / 2.00);
  int w = min(d, min(m, n - m));
  if (m == 0)
    cout << 1 << endl;
  else
    cout << w << endl;
  return 0;
}
