The present invention provides heterocyclic-substituted pyrrolopyridines and pyrrolopyrimidines of Formula I: wherein X, Y, Z, L, A, R5, n, m, and r are defined above, as well as their compositions and methods of use, that modulate the activity of Janus kinases (JAKs) and are useful in the treatment of diseases related to the activity of JAKs including, for example, inflammatory disorders, autoimmune disorders, cancer, and other diseases.本発明は、ヤヌスキナーゼ(JAK)の活性を調節し、例えば、炎症性障害、自己免疫障害、癌、および他の疾患を含む、JAKの活性に関連する疾患の治療において有用である、式I(式中、X、Y、Z、L、A、R5、n、m、およびrは上に定義される)の複素環置換ピロロピリジンおよびピロロピリミジン、ならびにそれらの組成物および使用方法を提供する。