The present invention relates to compounds of formula Iwherein A, B, X, Y, Ar, R1, R2, R′, m and n are as defined herein and to pharmaceutical active acid addition salts thereof.Compounds of formula I have a good affinity to the trace amine associated receptors (TAARs), especially for TAAR1. The compounds can be used for the treatment of depression, anxiety disorders, bipolar disorder, attention deficit hyperactivity disorder (ADHD), stress-related disorders, psychotic disorders such as schizophrenia, neurological diseases such as Parkinson's disease, neurodegenerative disorders such as Alzheimer's disease, epilepsy, migraine, hypertension, substance abuse and metabolic disorders such as eating disorders, diabetes, diabetic complications, obesity, dyslipidemia, disorders of energy consumption and assimilation, disorders and malfunction of body temperature homeostasis, disorders of sleep and circadian rhythm, and cardiovascular disorders.