Since LibreOffice 24.8, there is UNIQUE function, so now a simple
=COUNT(UNIQUE(B2:B5))
does the job.