#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int main() {
  int n, m, x = 1;
  int ma[maxn];
  cin >> n >> m;
  if (m == 0) {
    cout << "1" << endl;
    return 0;
  }
  if (m == n) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 1; i <= n / 2; i++) {
    ma[i] = i;
    ma[n - i] = i;
  }
  cout << ma[m] << endl;
  return 0;
}
