import sys import itertools import heapq import bisect from collections import deque, defaultdict from functools import lru_cache, cmp_to_key input = sys.stdin.readline # for AtCoder Easy test if __file__ != 'prog.py': sys.setrecursionlimit(10 ** 6) def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input().rstrip() P = int(input()) S = str(10 ** P) dp = [[[0, 0] for _ in range(2)] for _ in range(3)] dp[0][0][0] = 1 for i in range(len(S)): ndp = [[[0, 0] for _ in range(2)] for _ in range(3)] for j in range(3): for k in range(10): n = (j + k) % 3 if k == 3: ndp[n][1][1] += dp[j][1][1] + dp[j][0][1] else: ndp[n][1][1] += dp[j][1][1] ndp[n][0][1] += dp[j][0][1] if k < int(S[i]): if k == 3: ndp[n][1][1] += dp[j][1][0] + dp[j][0][0] else: ndp[n][1][1] += dp[j][1][0] ndp[n][0][1] += dp[j][0][0] elif k == int(S[i]): if k == 3: ndp[n][1][0] += dp[j][1][0] + dp[j][0][0] else: ndp[n][1][0] += dp[j][1][0] ndp[n][0][0] += dp[j][0][0] dp = ndp ans = 0 for i in range(3): for j in range(2): if i == 0 or j == 1: ans += sum(dp[i][j]) print(ans - 1)