The present invention relates to compounds of formula I wherein A, B, X, Y, Ar, R1, R2, R′, m and n are as defined herein and to pharmaceutical active acid addition salts thereof, which have a good affinity to the trace amine associated receptors TAAR1, so that they can be used for the treatment of depression, anxiety disorders and bipolar disorder.