#include <bits/stdc++.h>
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    if (m == 0) {
      printf("1\n");
      continue;
    }
    if (m <= n / 2)
      printf("%d\n", m);
    else {
      printf("%d\n", n - m);
    }
  }
}
