n=int(raw_input()) res=0 for i in range(1,n+1): s=str(i) if('1' in s or '2' in s or '0' in s or '9' in s): res+=i print(res)