Don't use Hash#first

Fixes #31360.