Provided is a compound having an excellent JAK inhibitory activity and therefore useful as a prophylactic or therapeutic agent for autoimmune diseases (e.g., rheumatoid arthritis, psoriasis, inflammatory bowel disease, Sjogren's syndrome, Behcet's disease, multiple sclerosis, systemic lupus erythematosus), cancer (e.g., leukemia, uterine leiomyosarcoma, prostate cancer, multiple myeloma, dyscrasia, bone marrow fibrosis) or the like, or a salt of the compound. The present invention relates to a compound represented by formula (I) [wherein each symbol is as defined in the description] or a salt thereof.