#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VI2 = vector<VI>;
using UM = unordered_map<int, int>;
using UM2 = unordered_map<int, UM>;
using M = map<int, int>;
using M2 = map<int, M>;
using u64 = unsigned long long;
using i64 = long long;
using u32 = unsigned int;
using USI = unordered_set<int>;
using USS = unordered_set<string>;
using VUS = vector<USI>;
int main() {
  int n, m;
  cin >> n >> m;
  VI a(n, 1);
  for (int j = 0; j < m; j++) {
    int ind = -1;
    int ind2 = -1;
    bool f = false;
    for (int i = 0; i < n; i++) {
      if (!a[i]) continue;
      ind2 = i;
      int ip1 = (i + 1) % n;
      int im1 = !i ? n - 1 : i - 1;
      int sc = 0;
      if (a[ip1]) sc++;
      if (a[im1]) sc++;
      if (sc == 2) {
        a[i] = 0;
        f = true;
        break;
      }
      if (ind >= 0 && sc == 1) {
        ind = i;
        break;
      }
    }
    if (ind >= 0) {
      a[ind] = 0;
      continue;
    }
    if (!f && ind2 < 0) {
      cout << "0\n";
      return 0;
    }
    if (!f) a[ind2] = 0;
  }
  int mgn = 1;
  if (a[0]) a[0] = mgn++;
  for (int i = 1; i < n; i++) {
    if (!a[i]) continue;
    if (a[i - 1])
      a[i] = a[i - 1];
    else
      a[i] = mgn++;
  }
  mgn--;
  if (a[0] && a[n - 1] && a[0] != a[n - 1]) {
    mgn--;
  }
  cout << mgn << "\n";
  return 0;
}
