#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n == m)
    cout << "0\n";
  else if (m == 0)
    cout << "1\n";
  else {
    int val = n - m;
    if (val < m)
      cout << val << "\n";
    else
      cout << m << "\n";
  }
}
