A man has been jailed after pleading guilty to breaching his Sexual Harm Prevention Order – having been spotted exposing himself at a public library in Derbyshire.