You should get 8 on both queries. A MAX() on a ROW_NUMBER() without PARTITION BY should give you the same values as COUNT(*).
The reason is that you have keyids 1 and 8 repeated. You could check it with a simple query.
SELECT *
from @a a
left outer join @b b
on a.keyid = b.keyid