#include <bits/stdc++.h>
using namespace std;
int arra[107];
int pos1[107];
int light[1008];
map<long long int, long long int> code;
map<long long int, long long int> vis;
vector<long long int> ans;
long long int position[2009];
vector<pair<long long int, long long int> > vect;
long long int zog[1000000];
int main() {
  long long int n, m, p, q, r, s, t, i, k, j, l = 2, profit = 0, sum = 0,
                                              one = 1, a, b, z = 4, zero = 0;
  cin >> n >> m;
  if (m == 0)
    cout << "1" << '\n';
  else {
    cout << min(n - m, m) << '\n';
  }
}
