//hdu2089 #include "cstdio" #include "cstring" #include "iostream" #include "algorithm" using namespace std; int cont; long long dig[10001]; long long dp[20][2][2]; int dfs(int pos,int six,int flag){ if (pos<0)return 1; long long ans=0; if (dp[pos][six][flag]!=-1)return dp[pos][six][flag]; for (int i = 0; i <= 9;i++){ if (i>dig[pos]&&flag==1)break; if (i==2&&six==1)continue; if (i==4)continue; ans=ans+dfs(pos-1,i==6,flag&&i==dig[pos]); } return dp[pos][six][flag]=ans; } long long s(long long x){ if (x<0)return 0; memset(dp,-1,sizeof(dp)); cont=0; while (x){ dig[cont++]=x%10; x=x/10; } return dfs(cont-1,0,1); } int main (){ long long n , m; while (~scanf ("%lld%lld",&n,&m)){ if (n==0&&m==0)break; printf ("%lld ",s(m)-s(n-1)); } }