#include <bits/stdc++.h>
using namespace std;
long long dp[10001];
set<pair<long long, long long>> s;
set<long long> X, Y;
long long a[300000], b[300000];
void solve(long long op, long long cl, string output, vector<string> &v) {
  if (op == 0 && cl == 0) {
    v.push_back(output);
  }
  if (op != 0) {
    string op1 = output;
    op1.push_back('(');
    solve(op - 1, cl, op1, v);
  }
  if (cl > op) {
    string op1 = output;
    op1.push_back(')');
    solve(op, cl - 1, op1, v);
  }
  return;
}
vector<string> fun(long long n) {
  vector<string> v;
  long long op = n;
  long long cl = n;
  string output = "";
  solve(op, cl, output, v);
  return v;
}
bool check(long long a[], long long n) {
  for (long long i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) return false;
  }
  return true;
}
long long countOddSquares(long long n, long long m) {
  return (long long)pow(m, 0.5) - (long long)pow(n - 1, 0.5);
}
bool chk(long long a1, long long a2, long long m) {
  for (long long i = 0; i < m; i++) {
    if (a[1] == a[i] or a1 == b[i] or a2 == b[i]) continue;
    if (a2 == -1)
      return (chk(a1, a[i], m) or chk(a1, b[i], m));
    else
      return 0;
  }
  return 1;
}
long long possible_to_divide(vector<long long> &A,
                             long long target_no_of_parts) {
  long long sum = 0;
  for (long long i = 1; i < A.size(); i++) sum += A[i];
  long long target_part_sum = sum / target_no_of_parts;
  long long parts_that_are_made = 0;
  for (long long current_part_sum = 0, i = 1; i < A.size(); i++) {
    current_part_sum += A[i];
    if (current_part_sum == target_part_sum) {
      parts_that_are_made++;
      current_part_sum = 0;
    }
    if (current_part_sum > target_part_sum) return false;
  }
  return (parts_that_are_made == target_no_of_parts);
}
long long countFreq(string &pat, string &txt) {
  long long M = pat.length();
  long long N = txt.length();
  long long res = 0;
  for (long long i = 0; i <= N - M; i++) {
    long long j;
    for (j = 0; j < M; j++)
      if (txt[i + j] != pat[j]) break;
    if (j == M) {
      res++;
      j = 0;
    }
  }
  return res;
}
long long reversDigits(long long num) {
  long long rev_num = 0;
  while (num > 0) {
    rev_num = rev_num * 10 + num % 10;
    num = num / 10;
  }
  return rev_num;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  {
    long long test;
    test = 1;
    while (test--) {
      long long n, k;
      cin >> n >> k;
      long long x = (n + 1) / 2;
      if (k == 0)
        cout << 1;
      else if (k == n)
        cout << 0;
      else if (k < x)
        cout << k;
      else
        cout << n - k;
    }
  }
}
