The present invention provides a compound having a cholinergic muscarinic M1 receptor positive allosteric modulator activity and useful as a medicament such as a prophylactic or therapeutic drug for Alzheimer's disease, schizophrenia, pain, sleep disorder, Parkinson's disease dementia, dementia with Lewy bodies and the like, and the like. The present invention relates to a compound represented by the formula (I) or a salt thereof. wherein each symbol is as described in the attached DESCRIPTION.