#include <bits/stdc++.h>
const double pi = 3.1415926;
using namespace std;
long long n, m;
int main() {
  cin >> n >> m;
  long long x = n, y = 0;
  if (m == 0) {
    cout << 1;
    return 0;
  }
  while (x > 1) {
    x = x - 2;
    y++;
    if (y == m) break;
  }
  if (y == m)
    cout << m;
  else {
    if (x == 1)
      cout << (n / 2) - (m - y - 1);
    else
      cout << (n / 2) - (m - y);
  }
  return 0;
}
