#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pt = complex<ll>;
struct slope {
  ll x, y;
  bool operator<(const slope& o) const { return x * o.y < o.x * y; }
  bool operator==(const slope& o) const { return x * o.y == o.x * y; }
};
struct edge {
  slope s;
  ld y;
  edge(pt a, pt b) {
    pt dist = a - b;
    s = {real(dist), imag(dist)};
    y = a.real() - (1.0l * a.imag() * s.y) / s.x;
    if (s.x == 0) y = a.real();
  }
  bool operator<(const edge& o) const {
    if (y != o.y) return y < o.y;
    return s < o.s;
  }
  bool operator==(const edge& o) const {
    return s == o.s && abs(y - o.y) < 1e-9;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  ll peek = n / 2;
  if (m <= peek) {
    cout << max(1ll, m) << endl;
  } else {
    if (n % 2 != 0 && m > 0) m--;
    cout << peek - (m - peek) << endl;
  }
}
