#include using namespace std; int main() { long long N, K; cin >> N >> K; long long ans = 0; if( 1 <= K && K <= N ) { ans = N - 2; K--; if( 1 + K == N - K ) ans = N - 1; } cout << ans << endl; }