//https://vjudge.net/problem/HDU-2089
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5 + 10;
int num[20];
ll f[20][2];
ll dfs(int pos, int pre, bool sta, bool limit)
{
if (pos == 0) return 1;
if (!limit && f[pos][sta] != -1) return f[pos][sta];
ll ans = 0;
int up = limit ? num[pos] : 9;
for (int i = 0; i <= up; i++)
{
if(i == 4 || pre == 6 && i == 2) continue;
ans += dfs(pos - 1, i, i == 6, limit && i == up);
}
if (!limit) f[pos][sta] = ans;
return ans;
}
ll run(ll x)
{
int len = 0;
while (x)
{
num[++len] = x % 10;
x /= 10;
}
memset(f, -1, sizeof f);
return dfs(len, 0, 0, 1);
}
void solve()
{
ll l, r;
while (cin >> l >> r, l || r)
cout << run(r) - run(l - 1) << '\n';
}
signed main()
{
IOS;
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
12-02
2102

12-01
4126

12-10
343
