#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, t, j, r, k, mn, mx = 0, l, x;
  cin >> n >> m;
  if (m == 0)
    cout << 1 << endl;
  else {
    r = n / 2;
    if (m <= r)
      cout << m << endl;
    else
      cout << n - m << endl;
  }
}
