#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a,b,f[13][13],num[13],tot,x;
void init(){
memset(f , 0 , sizeof(f));
for(int i = 0 ; i <= 9 ; i++)f[1][i] = 1;
f[1][4] = 0;
for(int i = 2 ; i <= 10 ; i++){
for(int j = 0 ; j <= 9 ; j++){
if(j == 4)continue;
for(int k = 0 ; k <= 9 ; k++){
f[i][j] += f[i - 1][k];
}
if(j == 6)f[i][j] -= f[i - 1][2];
}
}
}
ll cal(ll now){
x = now;
tot = 0;
ll ans = 0;
ll last;
while(x)num[++tot] = x % 10 , x = x / 10;
num[tot + 1] = 0;
for(int i = tot ; i >= 1 ; i--){
for(int j = 0 ; j < num[i] ; j++){
if(j == 2 && num[i + 1] == 6)continue;
if(j == 4)continue;
ans = ans + f[i][j];
}
if(num[i] == 4)break;
if(num[i] == 2 && num[i + 1] == 6)break;
}
return ans;
}
int main(){
init();
while(1){
cin>>a>>b;
if(!a && !b)break;
cout<<cal(b + 1) - cal(a)<<endl;
}
}