#include <bits/stdc++.h>
using namespace std;
int a[1001];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    a[i] = 1;
  }
  for (int i = 2; i <= n && m > 0; i += 2, --m) {
    a[i] = 0;
  }
  for (int i = 1; i <= n && m > 0; i += 2, --m) {
    a[i] = 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 0) {
      ++m;
      continue;
    }
    ans += (a[i - 1] == 0);
  }
  ans -= (a[1] == 1 && n > 1 && a[n] == 1);
  ans = max(1 * (m != n), ans);
  cout << ans << '\n';
  return 0;
}
