sub f{/ /,push@ $`,$'+!push@{$'+0},$`for<>;my($j,$p,$a)=@_;$a|=$_-$p&&f($_,$j)for@$j;$\+=!$a;!$a}f!!<>;print