A compound of Formula: or a pharmaceutically acceptable salt thereof, wherein: A is N or CR b; R a is selected from the group consisting of hydrogen and (C 1 -C 6) alkyl; R b is selected from the group consisting of hydrogen, halogen, OH, (C 1 -C 6) alkyl optionally substituted with one or more R 5, and (C 1 -C 6) alkoxy optionally substituted with one or more R 5; or R b and X together form a (C 3 -C 6) spirocyclic cycloalkyl or (C 3 -C 6) spirocyclic heterocycloalkyl; each of R c, R d, R e and R f is independently selected from the group consisting of hydrogen, halogen, -ORs and (C 1 -C 6) alkyl optionally substituted with one or more R 5; R 2 is selected from the group consisting of C N and N C; X is independently chosen from hydrogen, alkyl, and heteroalkyl, wherein the alkyl and heteroalkyl can optionally cyclize with R b or R 3; R 3 is selected from the group consisting of (C 1 -C 6) alkyl, (C 3 -C 6) cycloalkyl, (C 1 -C 6) heteroalkyl, aryl having 1 to 3 aromatic rings and optionally substituted with 1 or 2 R groups, and heteroaryl having 1 to 3 aromatic rings and optionally substituted with 1 or 2 R groups; R 4 is independently chosen from alkyl, cycloalkyl, heteroalkyl, haloalkyl, alkoxy, cycloalkoxy, heteroalkoxy, haloalkoxy, carboxyalkyl, heterocarboxyalkyl, cyclic, heterocyclic, aryl, and heteroaryl, wherein any rings are optionally substituted with 1 or 2 Y groups; R 5 is selected from the group consisting of hydrogen, halogen, OH, (C 1 -C 3) alkyl, and (C 1 -C 3) alkoxy; R is independently chosen from hydrogen, OH, CN, (C 1 -C 6) alkyl, (C 1 -C 6) alkoxy, (C 1 -C 6) haloalkyl, (C 1 -C 6) haloalkoxy, halogen, (C 3 -C 6) cycloalkyl, (C 3 -C 6) heterocycloalkyl, (C 3 -C 6) cycloalkyloxy, and (C 1 -C 6) alkoxyalkyl; Y is independently chosen from hydrogen, OH, CN, N 2, (C 1 -C 6) alkyl, (C 1 -C 6) heteroalkyl, (C 1 -C 6) alkoxy, (C 1 -C 6) haloalkyl, (C 1 -C 6) haloalkoxy, halogen, (C 3 -C 6) cycloalkyl, (C 3 -C 6) heterocycloalkyl, (C 5 -C 8) aryl, (C 4 -C 8) heteroaryl, and (C 4 -C 8) heteroaryl substituted with (C 1 -C 3) alkyl; and m is 0, 1, or 2. R a is selected from the group consisting of hydrogen and (C 1 -C 6) alkyl; R b is selected from the group consisting of hydrogen, halogen, OH, (C 1 -C 6) alkyl optionally substituted with one or more R 5, and (C 1 -C 6) alkoxy optionally substituted with one or more R 5; or R b and X together form a (C 3 -C 6) spirocyclic cycloalkyl or (C 3 -C 6) spirocyclic heterocycloalkyl; each of R c, R d, R e and R f is independently selected from the group consisting of hydrogen, halogen, -ORs and (C 1 -C 6) alkyl optionally substituted with one or more R 5; R 2 is selected from the group consisting of C N and N C; X is independently chosen from hydrogen, alkyl, and heteroalkyl, wherein the alkyl and heteroalkyl can optionally cyclize with R b or R 3; R 3 is selected from the group consisting of (C 1 -C 6) alkyl, (C 3 -C 6) cycloalkyl, (C 1 -C 6) heteroalkyl, aryl having 1 to 3 aromatic rings and optionally substituted with 1 or 2 R groups, and heteroaryl having 1 to 3 aromatic rings and optionally substituted with 1 or 2 R groups; R 4 is independently chosen from alkyl, cycloalkyl, heteroalkyl, haloalkyl, alkoxy, cycloalkoxy, heteroalkoxy, haloalkoxy, carboxyalkyl, heterocarboxyalkyl, cyclic, heterocyclic, aryl, and heteroaryl, wherein any rings are optionally substituted with 1 or 2 Y groups; R 5 is selected from the group consisting of hydrogen, halogen, OH, (C 1 -C 3) alkyl, and (C 1 -C 3) alkoxy; R is independently chosen from hydrogen, OH, CN, (C 1 -C 6) alkyl, (C 1 -C 6) alkoxy, (C 1 -C 6) haloalkyl, (C 1 -C 6) haloalkoxy, halogen, (C 3 -C 6) cycloalkyl, (C 3 -C 6) heterocycloalkyl, (C 3 -C 6) cycloalkyloxy, and (C 1 -C 6) alkoxyalkyl; Y is independently chosen from hydrogen, OH, CN, N 2, (C 1 -C 6) alkyl, (C 1 -C 6) heteroalkyl, (C 1 -C 6) alkoxy, (C 1 -C 6) haloalkyl, (C 1 -C 6) haloalkoxy, halogen, (C 3 -C 6) cycloalkyl, (C 3 -C 6) heterocycloalkyl, (C 5 -C 8) aryl, (C 4 -C 8) heteroaryl, and (C 4 -C 8) heteroaryl substituted with (C 1 -C 3) alkyl; and m is 0, 1, or 2.