Provided is a compound having an excellent JAK-inhibiting effect, the compound being is useful as an agent for the prevention or treatment of autoimmune diseases (rheumatoid arthritis, psoriasis, inflammatory bowel disease, Sjogren's syndrome, Behcet's disease, multiple sclerosis, systemic lupus erythematosus, and the like) and cancer (leukemia, uterine leiomyosarcoma, prostate cancer, multiple myeloma, cachexia, myelofibrosis, and the like) or a salt thereof. The invention relates to a compound represented by formula (I) [in the formula, each symbol is as defined in the specification] or a salt thereof.