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