#include <bits/stdc++.h>
using namespace std;
long long k[100000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  if (!m)
    cout << 1 << endl;
  else if (m <= n / 2)
    cout << m << endl;
  else
    cout << n - m << endl;
}
