N, K = gets.split.map(&:to_i) if N == 1 puts N elsif K == N puts K - 1 elsif N == 2 && K == 1 puts N elsif K == N - 1 puts N else puts N - 1 end