#include <stdio.h>
#include <string.h>
int main(void) {
int maxTurn = 0;
int total_claps = 0;
int i;
scanf("%d", &maxTurn);
while (i <= maxTurn) {
int current_number = i;
while (current_number > 0) {
int digit = current_number % 10;
if (digit == 3 || digit == 6 || digit == 9) {
total_claps++;
}
current_number /= 10;
}
i++;
}
printf("%d", total_claps);
}