#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

unsigned short INVALID = 0x7FFF;

struct less
{
    bool operator() (std::map<int, unsigned short>::value_type const& a, std::map<int, unsigned short>::value_type const& b)
    {
        if (a.second == INVALID || b.second == INVALID)
            return false;
        return a.second < b.second;
    }
};

int main()
{
    std::map<int, unsigned short> a;
    a[1] = INVALID;
    a[2] = 1;
    a[3] = 2;
    a[4] = 3;
	std::cout << "A max = " << std::max_element(a.begin(), a.end(), less())->second << std::endl;
	std::cout << "A min = " << std::min_element(a.begin(), a.end(), less())->second<< std::endl;
	
	std::map<int, unsigned short> b;
    b[1] = 1;
    b[2] = 2;
    b[3] = 3;
    b[4] = INVALID;
	std::cout << "B max = " << std::max_element(b.begin(), b.end(), less())->second << std::endl;
	std::cout << "B min = " << std::min_element(b.begin(), b.end(), less())->second << std::endl;
	
	
    return 0;
}
