process.stdin.resume();
process.stdin.setEncoding('utf8');
function countNumber(num) {
let count = 0;
while (num > 0) {
const digit = num % 10;
if (digit === 3 || digit === 6|| digit === 9) {
count++;
}
num = Math.floor(num / 10);
}
return count;
}
function countInRange(first, last){
let count = 0;
for(let i = first; i< last; i++){
count+=countNumber(i)
}
return count
}
var remainder = ''
process.stdin.on('data', function (chunk) {
const input = chunk.toString().split(' ')
const maxNumber = input[1].length
const minNumber = input[0].length
let result = 0
if(maxNumber-minNumber > 1){
let i = minNumber+1
while(i <= maxNumber-1){
result+=(Math.pow(10,i-1) + 9*(i-1)*Math.pow(10,i-2))*3;
i++
}
result+=countInRange(Number(input[0]), Math.pow(10,minNumber))
result+=countInRange(Math.pow(10,maxNumber-1), Number(input[1]) )
}
else {
result = countInRange(Number(input[0]), Number(input[1]))
}
console.log(result)
});
cHJvY2Vzcy5zdGRpbi5yZXN1bWUoKTsKcHJvY2Vzcy5zdGRpbi5zZXRFbmNvZGluZygndXRmOCcpOwoKZnVuY3Rpb24gY291bnROdW1iZXIobnVtKSB7CiAgbGV0IGNvdW50ID0gMDsKICB3aGlsZSAobnVtID4gMCkgewogICAgY29uc3QgZGlnaXQgPSBudW0gJSAxMDsKICAgIGlmIChkaWdpdCA9PT0gMyB8fCBkaWdpdCA9PT0gNnx8IGRpZ2l0ID09PSA5KSB7CiAgICAgIGNvdW50Kys7CiAgICB9CiAgICBudW0gPSBNYXRoLmZsb29yKG51bSAvIDEwKTsKICB9CiAgcmV0dXJuIGNvdW50Owp9CiAKIApmdW5jdGlvbiBjb3VudEluUmFuZ2UoZmlyc3QsIGxhc3QpewogICAgbGV0IGNvdW50ID0gMDsKICAgIGZvcihsZXQgaSA9IGZpcnN0OyBpPCBsYXN0OyBpKyspewogICAgICAgIGNvdW50Kz1jb3VudE51bWJlcihpKQogICAgfQogICAgcmV0dXJuIGNvdW50Cn0KCnZhciByZW1haW5kZXIgPSAnJwpwcm9jZXNzLnN0ZGluLm9uKCdkYXRhJywgZnVuY3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