#include <iostream>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
string N;
ll memo[20][11][11][2][2];
ll dp(int pos, int prev1, int prev2, bool tight, bool leading_zero) {
if (pos == N.size()) {
return 1; // We have formed a valid number
}
if (memo[pos][prev1 + 1][prev2 + 1][tight][leading_zero] != -1) {
return memo[pos][prev1 + 1][prev2 + 1][tight][leading_zero];
}
ll res = 0;
int limit = tight ? N[pos] - '0' : 9;
for (int d = 0; d <= limit; ++d) {
bool new_tight = tight && (d == limit);
bool new_leading_zero = leading_zero && (d == 0);
int new_prev1 = prev1, new_prev2 = prev2;
if (new_leading_zero) {
// Leading zeros, prev1 and prev2 remain -1
res += dp(pos + 1, -1, -1, new_tight, true);
} else {
// Check for palindromic substrings
if (prev1 == d) continue; // Palindrome of length 2
if (prev2 == d) continue; // Palindrome of length 3
new_prev2 = prev1;
new_prev1 = d;
res += dp(pos + 1, new_prev1, new_prev2, new_tight, false);
}
}
return memo[pos][prev1 + 1][prev2 + 1][tight][leading_zero] = res;
}
ll count(string num) {
N = num;
memset(memo, -1, sizeof(memo));
return dp(0, -1, -1, true, true);
}
int main() {
ll a, b;
cin >> a >> b;
if (a > b) swap(a, b); // Ensure a <= b
ll ans = count(to_string(b)) - (a > 0 ? count(to_string(a - 1)) : 0);
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPHN0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCnN0cmluZyBOOwpsbCBtZW1vWzIwXVsxMV1bMTFdWzJdWzJdOwoKbGwgZHAoaW50IHBvcywgaW50IHByZXYxLCBpbnQgcHJldjIsIGJvb2wgdGlnaHQsIGJvb2wgbGVhZGluZ196ZXJvKSB7CiAgICBpZiAocG9zID09IE4uc2l6ZSgpKSB7CiAgICAgICAgcmV0dXJuIDE7IC8vIFdlIGhhdmUgZm9ybWVkIGEgdmFsaWQgbnVtYmVyCiAgICB9CiAgICBpZiAobWVtb1twb3NdW3ByZXYxICsgMV1bcHJldjIgKyAxXVt0aWdodF1bbGVhZGluZ196ZXJvXSAhPSAtMSkgewogICAgICAgIHJldHVybiBtZW1vW3Bvc11bcHJldjEgKyAxXVtwcmV2MiArIDFdW3RpZ2h0XVtsZWFkaW5nX3plcm9dOwogICAgfQogICAgbGwgcmVzID0gMDsKICAgIGludCBsaW1pdCA9IHRpZ2h0ID8gTltwb3NdIC0gJzAnIDogOTsKICAgIGZvciAoaW50IGQgPSAwOyBkIDw9IGxpbWl0OyArK2QpIHsKICAgICAgICBib29sIG5ld190aWdodCA9IHRpZ2h0ICYmIChkID09IGxpbWl0KTsKICAgICAgICBib29sIG5ld19sZWFkaW5nX3plcm8gPSBsZWFkaW5nX3plcm8gJiYgKGQgPT0gMCk7CiAgICAgICAgaW50IG5ld19wcmV2MSA9IHByZXYxLCBuZXdfcHJldjIgPSBwcmV2MjsKICAgICAgICBpZiAobmV3X2xlYWRpbmdfemVybykgewogICAgICAgICAgICAvLyBMZWFkaW5nIHplcm9zLCBwcmV2MSBhbmQgcHJldjIgcmVtYWluIC0xCiAgICAgICAgICAgIHJlcyArPSBkcChwb3MgKyAxLCAtMSwgLTEsIG5ld190aWdodCwgdHJ1ZSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgLy8gQ2hlY2sgZm9yIHBhbGluZHJvbWljIHN1YnN0cmluZ3MKICAgICAgICAgICAgaWYgKHByZXYxID09IGQpIGNvbnRpbnVlOyAvLyBQYWxpbmRyb21lIG9mIGxlbmd0aCAyCiAgICAgICAgICAgIGlmIChwcmV2MiA9PSBkKSBjb250aW51ZTsgLy8gUGFsaW5kcm9tZSBvZiBsZW5ndGggMwogICAgICAgICAgICBuZXdfcHJldjIgPSBwcmV2MTsKICAgICAgICAgICAgbmV3X3ByZXYxID0gZDsKICAgICAgICAgICAgcmVzICs9IGRwKHBvcyArIDEsIG5ld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