Constraining Gluon Distributions in Nuclei Using Dijets in Proton-Proton and Proton-Lead Collisions at sNN =5.02 TeV