import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); int length = arr.length; if (length > 2) { int[][] dp = new int[length + 1][2]; dp[0][0] = 1; for (int i = 1; i <= length; i++) { int a = arr[i - 1] - '0'; if (a % 3 == 0) { dp[i][0] += dp[i - 1][0]; } dp[i][1] += dp[i - 1][0] * ((a + 2) / 3); dp[i][1] += dp[i - 1][1] * 4; } int count = dp[length][0] + dp[length][1] - 4; for (int i = 10; i <= 99; i++) { if (i % 10 % 3 != 0 && (i % 10 + i / 10) % 3 == 0) { count++; } } System.out.println(count); } else { int count = 0; for (int i = 10; i <= Integer.parseInt(new String(arr)); i++) { if ((i % 10 + i / 10) % 3 == 0) { count++; } } System.out.println(count); } } }