#include <bits/stdc++.h>
using namespace std;
bool nai[1005];
int main() {
  int i, n, m, count = 0;
  cin >> n >> m;
  if (m == 0) {
    cout << 1 << endl;
    return 0;
  }
  if (n == m) {
    printf("0\n");
    return 0;
  }
  int r = 1;
  for (i = 0; i < m; i++) {
    if (r > n) {
      r = 2;
    }
    nai[r] = 1;
    r += 2;
  }
  int flag = 0;
  for (i = 1; i <= n; i++) {
    if (!nai[i] && !flag) {
      count++;
      flag = 1;
    }
    if (nai[i] && flag) {
      flag = 0;
    }
  }
  cout << count << endl;
}
