#include <iostream>
#include <string>
bool isClap(int digit) {
return digit == 3 || digit == 6 || digit == 9;
}
// Input validation
bool checkInput(long long& a, long long& b) {
// Read two integers from input
if (!(std::cin >> a >> b))
return false;
std::cin >> std::ws;
char c;
// Check for extra characters (must be newline)
if (std::cin.get(c) && c != '\n')
return false;
return (a >= 1 && b <= 100000000 && a <= b);
}
// Count occurrences of 3, 6, 9 in numbers from 1 to n
long long countClaps(long long n) {
std::string S = std::to_string(n);
int lengthOfNumber = S.size();
long long count = 0;
long long right_multiplier = 1;
for (int pos = lengthOfNumber - 1; pos >= 0; --pos) {
int currentNumber = S[pos] - '0';
// Get number formed by digits to the left of current position
long long leftValue = (pos == 0) ? 0 : std::stoll(S.substr(0, pos));
// Get number formed by digits to the right of current position
long long rightValue = (pos == lengthOfNumber - 1) ? 0 : std::stoll(S.substr(pos + 1));
count += leftValue * right_multiplier * 3;
for (int d = 0; d < currentNumber; ++d) {
if (isClap(d))
count += right_multiplier;
}
if (isClap(currentNumber))
count += rightValue + 1;
right_multiplier *= 10;
}
return count;
}
// Calculate claps from a to b
long long solve(long long a, long long b) {
return countClaps(b) - countClaps(a - 1);
}
int main() {
long long a, b;
if (!checkInput(a, b)) {
std::cout << "Invalid input! Please enter two integers a and b (1 <= a <= b <= 100000000) separated by a space." << std::endl;
return 1;
}
std::cout << solve(a, b) << std::endl;
return 0;
}