The present invention has an excellent Tyk2 inhibitory action and prevents or treats autoimmune diseases (eg, psoriasis, rheumatoid arthritis, inflammatory bowel disease, Sjogren's syndrome, Behcet's disease, multiple sclerosis, systemic lupus erythematosus, etc.) Provide the agent. The present invention is directed to the formula [wherein each symbol is as defined herein. ] Or a salt thereof.本発明は、優れたTyk2阻害作用を有し、自己免疫疾患(例、乾癬、関節リウマチ、炎症性腸疾患、シェーグレン症候群、ベーチェット病、多発性硬化症、全身性エリテマトーデス等)等の予防または治療剤を提供する。 本発明は、式[式中、各記号は本明細書中で定義した通りである。]で表される化合物またはその塩に関する。