#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
  int n, m;
  while (~scanf("%d %d", &n, &m)) {
    int maxx, dao, ans;
    if (m == 0)
      ans = 1;
    else if (n % 2 == 1) {
      maxx = (n - 1) / 2;
      int dao1 = n / 2;
      int dao2 = (n + 1) / 2;
      dao = (m <= dao1) ? dao1 : dao2;
      ans = maxx - abs(m - dao);
    } else {
      maxx = n / 2;
      dao = n / 2;
      ans = maxx - abs(m - dao);
    }
    printf("%d\n", ans);
  }
  return 0;
}
