Traverse the map and find minimum element with frequency k .
int res = INT_MAX ; for ( auto it = m . begin ( ) ; it != m . end ( ) ; ++ it ) if ( it -> second == k ) res = min ( res , it -> first ) ; return ( res != INT_MAX ) ? res : -1 ; }