#include <bits/stdc++.h>
FILE *in = stdin;
FILE *out = stdout;
int main() {
  int i, j, k;
  int n, m;
  fscanf(in, "%d %d", &n, &m);
  if (m == 0 || m == 1) {
    fprintf(out, "1");
    return 0;
  }
  k = std::min(m, n - m);
  fprintf(out, "%d", k);
  return 0;
}
