This document provides compounds of formula (I) or pharmaceutically acceptable salts thereof, wherein n, m, A1, A2, A3, A4, A5, A6, L1, L2, R1, R2, R3, Y, and Z are as defined herein. This document also provides pharmaceutical compositions comprising compounds of formula (I) or pharmaceutically acceptable salts thereof, and methods of using compounds of formula (I) or pharmaceutically acceptable salts thereof, for example, for treating diseases or conditions that can be treated by administration of orexin agonists.