Azhar Ali's maiden Test hundred helped Pakistan take a 42-run lead in the first innings of the second Test against Sri Lanka in Dubai.