Along with jail time, a Montana judge sentenced two men who lied about being vets to do some homework — and eat some humble pie.

Cascade County District Judge Greg Pinski ordered the men to handwrite the names of all 6,756 Americans killed in Iraq and Afghanistan, rewrite the obits for the 40 Montanans among them, and write apologies to veterans groups they fooled.

And when they’re paroled, they’ll have to stand at the Montana Veterans Memorial for eight hours on Memorial Day and Veterans Day — with signs saying, “I am a liar. I am not a veteran. I stole valor. I have dishonored veterans.”

“I want to make sure that my message is received loud and clear by these two defendants,” Pinski said.

Defendants Troy Allen Nelson, 33, and Ryan Patrick Morris, 28, lied about their military service to get their criminal cases transferred to Veterans Court, where vets can get more lenient treatment because of their service and the lingering effects of PTSD.

Nelson, who was convicted of drug possession, lied about having served to get in.

Morris was convicted of burglary and violating parole but claimed he did seven combat tours in 2016 — and lied that he was injured by a bomb and got off with community service.

When the ruse was exposed, Nelson got five years and Morris 10 — with Pinski promising to suspend three years from each sentence if they completed their homework.

Both will also have to do 441 hours of community service, or one hour for each Montanan killed in action since the Korean War.

Attorneys for both men objected to the public shaming that would come from standing at the veterans memorial in Great Falls holding self-effacing placards.

With Post wires