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