The present invention provides a compound having a cholinergic muscarinic M1 receptor positive allosteric modulator activity and useful as an agent for the prophylaxis or treatment of Alzheimer's disease, schizophrenia, pain, sleep disorder, Parkinson's disease dementia, dementia with Lewy bodies, 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 specification, or a salt thereof.