#include<iostream>#include<vector>usingnamespace std;constint N =12;int f[N][N];voidinitialize(){for(int i =0; i <=9;++ i) f[1][i]= i !=4;for(int i =2; i < N;++ i){for(int j =0; j <=9;++ j){if(j ==4)continue;for(int k =0; k <=9;++ k){if(k ==4||(j ==6&& k ==2))continue;
f[i][j]+= f[i -1][k];}}}}intcount(int n){if(n ==0)return1;
vector<int> a;while(n >0){
a.push_back(n %10);
n /=10;}int res =0, last =0;for(int i = a.size()-1; i >=0;-- i){int val = a[i];for(int j =0; j < val;++ j){if(j ==4||(last ==6&& j ==2))continue;
res += f[i +1][j];}if(val ==4||(last ==6&& val ==2))break;
last = val;if(i ==0)++ res;}return res;}intmain(){initialize();int l, r;while(cin >> l >> r, l || r)
cout <<count(r)-count(l -1)<< endl;return0;}