#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return ((x * y) / gcd(x, y)); }
char x[9];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, c = 0, i = 0;
  cin >> n >> m;
  if (m == 0) {
    cout << 1;
    return 0;
  }
  int *x = new int[n];
  fill(x, x + n, 1);
  while (m--) {
    if (i >= n) i = 1;
    x[i] = 0;
    i += 2;
  }
  for (int j = 0; j < n; j++) {
    if (x[j] == 1) {
      c++;
      while (j < n && x[j] == 1) j++;
    }
  }
  if (x[0] == 1 && x[n - 1] == 1) c--;
  cout << c;
  return 0;
}
