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