On the basis of a cathepsin S inhibitory effect, an excellent agent for treating or preventing autoimmune disease, allergic disease, graft rejection of an organ, bone marrow or tissue, systemic lupus erythematosus, or the like is provided. It was found that a nitrogen-containing bicyclic heterocyclic compound has an excellent cathepsin S inhibitory effect, thereby completing the invention. The compound of the present invention has an cathepsin S inhibitory effect, and can be used as an agent for preventing and/or treating autoimmune disease, allergic disease, graft rejection of an organ, bone marrow or tissue, systemic lupus erythematosus, or the like.