How to check if matrix block type is empty or not
You can fetch the number of entries for the first type, check if you receive an empty array if so fetch matrix blocks of type B

{% set blocksTypeOne = entry.matrixFieldHandle.type('blockTypeHandle1').find() %}
{% if blocksTypeOne|length %}
     // blocks with type A exists
{% else %}
    {% set blocksWithTwo = entry.matrixFieldHandle.type('blockTypeHandle2').find()
    // do something with them
{% endif %}