#include <bits/stdc++.h>
using namespace std;
const int MAX = 100006, MOD = 1e9 + 7;
bool arr[MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, m;
  int ind = 1;
  cin >> n >> m;
  if (n == m) return cout << "0\n", 0;
  if (!m) return cout << "1\n", 0;
  while (m--) {
    arr[ind] = true;
    ind += 2;
    if (ind > n) ind = 2;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (!arr[i] && arr[i - 1]) ans++;
  cout << ans << "\n";
}
