The first element. Constant time on average: the map keeps a lower bound on its first non-empty bucket, which insertion lowers and erase(iterator) raises, so while (!m.empty()) m.erase(m.begin()); is linear. begin() itself writes nothing, so concurrent calls are safe.