#!/usr/bin/env perl use strict; use warnings; my ($n, $k) = split / /, <>; chomp $k; if ($k <= 0 || $k > $n) { print 0; } else { if ($k * 2 == $n + 1) { print $n - 1; } else { print $n - 2; } }