#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  if (n == m) {
    cout << "0";
    return 0;
  }
  if (m == 0 || m == 1) {
    cout << "1";
    return 0;
  }
  if ((n - m) <= m) {
    cout << n - m;
  } else {
    int g = 2;
    m = m - 2;
    while (m != 0) {
      g += 1;
      m--;
    }
    cout << g;
  }
  return 0;
}
