P = int(input()) N = str(10**P-1) dp = [[[0]*3 for _ in range(2)] for _ in range(len(N)+1)] dp[0][0][0] = 1 for i in range(len(N)): for j in range(2): for k in range(3): for l in range(10): dp[i+1][j or l==3][(k*10+l)%3] += dp[i][j][k] ans = sum(dp[len(N)][1])+dp[len(N)][0][0]-1 ans += 10**P%3 == 0 print(ans)