The present invention provides heteroaryl substituted pyrrolo[2,3-b]pyridines (I) and heteroaryl substituted pyrrolo[2,3-b]pyrimidines that modulate the activity of Janus kinases and are useful in the treatment of diseases related to activity of Janus kinases including, for example, immune-related diseases, skin disorders, myeloid proliferative disorders, cancer, and other diseases.