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