#include <bits/stdc++.h>
using namespace std;
long long n, bcount, acount, m, len = 0, k, z;
vector<vector<long long>> map;
vector<vector<long long>> b;
vector<long long> arr;
vector<bool> check;
int maximum = 0;
int xnum1, ynum1, xnum2, ynum2;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  if (m == 0) {
    cout << 1;
  } else if (m == n) {
    cout << 0;
  } else if (m > n / 2) {
    cout << n - m;
  } else {
    cout << m;
  }
}
