This paper introduces a solution (team ISIBrno-AIMT) to the unofficial round of PhysioNet Challenge 2022. The main goal of the challenge was a classification of heart murmurs from phonocardiographic recordings into three mutually exclusive classes (i.e., present, unknown, and not present). We introduced a classification method based on the ResNet architecture with a multi-head attention mechanism. The model is optimized using a mixture of loss functions, i.e., binary cross-entropy and custom challenge score loss function that provides a differentiable approximation of challenge score. The objective challenge function was generally designed to reflect the cost of algorithmic pre-screening, expert screening, treatment, and missed diagnoses. Our proposed solution was ranked 1st (out of 166 submissions) in the unofficial challenge round, achieving a challenge score of 464. The cost of general practitioner screening of all patients in the publicly available dataset is approximately 540. Therefore our solution might be potentially cost-saving.