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
Craft 2
{% 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 %}
Update Craft 4 has finally dropped the .find()
method
{% set blocksTypeOne = clone(entry.matrixFieldHandle).type('blockTypeHandle1').all() %}
{% if blocksTypeOne|length %}
// blocks with type A exists
{% else %}
{% set blocksWithTwo = clone(entry.matrixFieldHandle).type('blockTypeHandle2').all()
// do something with them
{% endif %}