import java.util.Scanner; public class Main_yukicoder220 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int p = sc.nextInt(); long[] dp = new long[p + 1]; long[][] dp2 = new long[3][p + 1]; long base = 1; for (int i = 1; i <= p; i++) { for (int j = 0; j < 10; j++) { if (j == 3) { dp[i] += base; } else { dp[i] += dp[i - 1]; if (base == 1) { dp2[j % 3][i]++; } else { for (int k = 0; k < 3; k++) { dp2[(int)((base * j + k) % 3)][i] += dp2[k][i - 1]; } } } } base *= 10; } System.out.println(dp[p] + dp2[0][p] - 1); sc.close(); } }