#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (m == 0)
    cout << 1;
  else if (m == 1)
    cout << 1;
  else if (m <= n / 2) {
    cout << m;
  } else {
    cout << n - m;
  }
  cout << '\n';
  return 0;
}
