Provided is a compound having a melanin-concentrating hormone receptor antagonistic action and is useful as an agent for the prophylaxis or treatment of obesity and the like. A compound represented by the formula (I):wherein each symbol is as defined in the specification,or a salt thereof.