#include <bits/stdc++.h>
int present[1010];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) > 0) {
    if (m == 0) {
      printf("1\n");
      continue;
    }
    for (int i = 0; i < n; i++) present[i] = true;
    int i = 0;
    while (m--) {
      while (!present[i]) i = (i + 1) % n;
      present[i] = false;
      i = (i + 2) % n;
    }
    int ans = 0;
    i = 0;
    while (i < n) {
      if (present[i] and !present[(i - 1 + n) % n]) ans++;
      i++;
    }
    printf("%d\n", ans);
  }
}
