#include <iostream>
#include <vector>
#include <cstring> // For memset
typedef long long ll;
using namespace std;
const int MAX_K = 5;
const int MAX_LAST_K = 10000; // 10^(K - 1)
const int MAX_DIGIT = 10;
bool hasPalindrome[MAX_LAST_K][MAX_DIGIT];
void calculateHasPalindromeTable() {
for (int lastK = 0; lastK < MAX_LAST_K; ++lastK) {
vector<int> lastKDigits(MAX_K - 1);
int temp = lastK;
for (int i = MAX_K - 2; i >= 0; --i) {
lastKDigits[i] = temp % 10;
temp /= 10;
}
for (int digit = 0; digit < MAX_DIGIT; ++digit) {
vector<int> newLastKDigits = lastKDigits;
newLastKDigits.push_back(digit);
bool foundPalindrome = false;
int n = newLastKDigits.size();
for (int l = 2; l <= MAX_K && l <= n; ++l) {
bool isPalindrome = true;
for (int i = 0; i < l / 2; ++i) {
if (newLastKDigits[n - l + i] != newLastKDigits[n - i - 1]) {
isPalindrome = false;
break;
}
}
if (isPalindrome) {
foundPalindrome = true;
break;
}
}
hasPalindrome[lastK][digit] = foundPalindrome;
}
}
}
ll dp[20][MAX_LAST_K][2][2];
string numberString;
void initializeDP() {
memset(dp, -1, sizeof(dp));
}
ll solveDp(int position, int lastK, bool tight, bool leadingZero) {
if (position == numberString.length()) {
return leadingZero ? 0 : 1;
}
int tightIndex = tight ? 1 : 0;
int leadingZeroIndex = leadingZero ? 1 : 0;
if (dp[position][lastK][tightIndex][leadingZeroIndex] != -1) {
return dp[position][lastK][tightIndex][leadingZeroIndex];
}
int limit = tight ? numberString[position] - '0' : 9;
ll result = 0;
for (int digit = 0; digit <= limit; ++digit) {
bool newTight = tight && (digit == limit);
bool nextLeadingZero = leadingZero && (digit == 0);
if (nextLeadingZero) {
result += solveDp(position + 1, lastK, newTight, nextLeadingZero);
} else {
if (hasPalindrome[lastK][digit]) {
continue; // Skip if adding 'digit' forms a palindrome
}
int newLastK = (lastK * 10 + digit) % MAX_LAST_K;
result += solveDp(position + 1, newLastK, newTight, false);
}
}
dp[position][lastK][tightIndex][leadingZeroIndex] = result;
return result;
}
ll countPalinFree(ll n) {
if (n < 0) return 0;
numberString = to_string(n);
initializeDP();
return solveDp(0, 0, true, true);
}
int main() {
ll a, b;
cin >> a >> b;
calculateHasPalindromeTable();
ll result;
if (a == 0) {
result = countPalinFree(b);
} else {
result = countPalinFree(b) - countPalinFree(a - 1);
}
cout << result << endl;
return 0;
}