#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m;
  cin >> n >> m;
  if (m == 1 || m == 0) {
    cout << 1;
  } else if (m == n) {
    cout << 0;
  } else {
    if (m <= n / 2) {
      cout << m;
    } else {
      cout << n - m;
    }
  }
}
int main() { solve(); }
