#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1.0);
long long mod = 1e9 + 7;
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
long long prod(long long a, long long b) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1ll) res = (res + a) % mod;
    a = (2ll * a) % mod;
    b >>= 1ll;
  }
  return res;
}
long long power(long long a, long long b) {
  long long res = 1ll;
  while (b > 0) {
    if (b % 2ll) res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2ll;
  }
  return res;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  if (m == n) {
    cout << 0 << "\n";
  } else if (m <= 1) {
    cout << 1 << "\n";
  } else {
    n--, m--;
    vector<long long> a;
    long long i;
    for (i = 1; i <= (n + 1) / 2; i++) {
      a.push_back(i);
    }
    i--;
    if (n % 2) i--;
    for (; i > 0; i--) {
      a.push_back(i);
    }
    cout << a[m] << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
