@(n,m)sum(sum(diff((perms(1:n))')>0)==m)

ans(7,4)