#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll A,B,num[2505],n,sum[5005];
bool t[2000005];
const ll lb=2e6;
ll biao[5005]={0,527378,527287,527349,527393,527416,527337,527382,527326,527380,527346,527333,527335,527359,527350,527282,527346,527374,527372,527338,527314,527350,527361,527366,527372,527373,527347,527350,527342,527342,527336,527365,527378,527364,527365,527389,527349,527377,527345,527341,527358,527348,527352,527334,527412,527401,527368,527341,527376,527379,527355,527341,527361,527355,527339,527340,527344,527371,527350,527363,527356,527350,527357,527356,527372,527360,527370,527379,527343,527376,527337,527350,527336,527334,527364,527317,527380,527341,527366,527341,527347,527348,527327,527371,527367,527383,527350,527396,527340,527368,527351,527346,527361,527346,527347,527337,527374,527338,527359,527346,527383,527348,527342,527354,527357,527324,527345,527352,527352,527368,527342,527354,527344,527373,527332,527325,527362,527364,527334,527344,527360,527383,527347,527334,527372,527350,527352,527343,527381,527369,527344,527344,527342,527359,527348,527354,527341,527357,527370,527352,527340,527362,527353,527355,527334,527320,527330,527364,527331,527327,527308,527357,527357,527339,527339,527359,527372,527369,527343,527343,527345,527369,527363,527333,527342,527379,527351,527361,527355,527383,527348,527331,527383,527380,527343,527342,527356,527365,527355,527363,527341,527345,527369,527372,527358,527347,527356,527334,527346,527337,527362,527347,527342,527325,527321,527362,527345,527342,527356,527339,527358,527353,527350,527362,527378,527356,527340,527338,527360,527373,527338,527360,527333,527369,527357,527345,527338,527372,527381,527348,527358,527346,527361,527357,527379,527367,527341,527351,527340,527352,527353,527362,527356,527343,527362,527369,527359,527373,527354,527368,527338,527374,527372,527339,527372,527373,527354,527338,527363,527345,527342,527364,527351,527352,527350,527361,527356,527359,527355,527351,527343,527348,527348,527360,527348,527375,527359,527348,527339,527353,527352,527352,527376,527358,527342,527351,527338,527374,527344,527344,527350,527342,527352,527357,527347,527355,527360,527330,527337,527377,527334,527352,527363,527369,527339,527343,527341,527350,527373,527350,527345,527347,527358,527337,527368,527379,527350,527372,527359,527353,527349,527369,527359,527355,527366,527366,527355,527372,527351,527348,527360,527357,527350,527356,527371,527363,527349,527348,527359,527363,527341,527343,527355,527337,527393,527405,527348,527362,527353,527359,527336,527343,527352,527359,527393,527408,527338,527357,527347,527364,527345,527357,527361,527349,527371,527350,527339,527364,527354,527344,527351,527364,527337,527334,527364,527358,527342,527366,527388,527385,527339,527328,527342,527352,527338,527352,527363,527350,527385,527369,527354,527345,527343,527336,527359,527352,527350,527356,527358,527360,527348,527349,527346,527349,527338,527378,527375,527360,527354,527337,527358,527347,527331,527341,527367,527377,527360,527357,527357,527365,527350,527337,527363,527361,527338,527335,527361,527377,527348,527354,527350,527352,527375,527347,527361,527347,527353,527351,527341,527346,527346,527369,527346,527347,527395,527417,527346,527368,527364,527362,527345,527348,527323,527355,527400,527395,527348,527372,527387,527366,527346,527344,527362,527358,527348,527342,527356,527372,527358,527357,527363,527344,527361,527321,527370,527367,527352,527357,527353,527352,527339,527350,527359,527346,527366,527368,527366,527360,527389,527353,527354,527354,527328,527356,527363,527362,527351,527352,527384,527370,527363,527355,527358,527363,527339,527350,527354,527364,527340,527360,527369,527363,527354,527361,527351,527355,527352,527333,527354,527355,527359,527347,527376,527350,527369,527344,527352,527363,527339,527352,527359,527352,527334,527350,527366,527367,527354,527354,527345,527376,527357,527338,527346,527355,527356,527325,527362,527357,527365,527335,527361,527356,527353,527364,527369,527352,527344,527338,527347,527345,527343,527336,527361,527354,527354,527357,527368,527340,527347,527346,527361,527346,527348,527355,527371,527384,527344,527364,527352,527362,527356,527348,527349,527340,527338,527346,527340,527398,527374,527358,527337,527379,527359,527367,527348,527357,527358,527349,527342,527352,527346,527345,527354,527339,527362,527357,527362,527357,527355,527360,527353,527337,527361,527360,527374,527352,527343,527353,527358,527366,527331,527347,527350,527350,527354,527370,527352,527380,527351,527343,527366,527360,527357,527356,527354,527351,527344,527350,527364,527354,527358,527339,527353,527361,527374,527356,527384,527360,527358,527356,527341,527355,527349,527370,527361,527365,527362,527352,527357,527355,527349,527349,527347,527375,527357,527365,527365,527369,527346,527353,527355,527358,527344,527364,527357,527352,527359,527369,527358,527357,527373,527345,527361,527345,527352,527342,527346,527371,527350,527354,527342,527352,527340,527362,527360,527368,527362,527378,527357,527383,527335,527350,527339,527362,527351,527321,527350,527370,527359,527352,527363,527345,527344,527357,527351,527368,527353,527363,527345,527355,527349,527333,527363,527344,527347,527349,527363,527340,527355,527350,527375,527348,527340,527354,527347,527343,527356,527355,527352,527351,527338,527352,527340,527358,527358,527360,527363,527363,527364,527353,527347,527348,527342,527340,527337,527351,527342,527340,527339,527355,527374,527357,527361,527353,527361,527355,527367,527365,527360,527359,527346,527349,527350,527329,527349,527344,527358,527373,527341,527382,527326,527370,527348,527363,527344,527349,527365,527359,527377,527340,527373,527345,527346,527350,527342,527356,527349,527360,527340,527354,527377,527341,527365,527348,527359,527352,527352,527349,527359,527340,527369,527344,527340,527367,527352,527350,527361,527347,527353,527342,527367,527354,527359,527341,527335,527348,527342,527365,527332,527351,527340,527375,527348,527361,527380,527350,527351,527361,527361,527358,527358,527363,527342,527357,527360,527356,527355,527380,527336,527350,527357,527362,527341,527385,527363,527374,527348,527362,527347,527371,527348,527362,527339,527356,527351,527343,527368,527356,527358,527354,527356,527360,527370,527356,527362,527377,527331,527383,527357,527384,527340,527350,527354,527348,527350,527354,527361,527353,527341,527339,527364,527358,527340,527371,527343,527358,527349,527379,527347,527380,527361,527358,527352,527364,527344,527362,527350,527355,527347,527336,527361,527362,527347,527363,527354,527337,527349,527358,527348,527365,527356,527355,527352,527365,527352,527359,527353,527371,527357,527339,527351,527343,527339,527355,527361,527348,527347,527383,527355,527361,527351,527354,527347,527347,527370,527334,527367,527365,527341,527351,527350,527341,527340,527347,527360,527367,527349,527354,527361,527356,527337,527348,527365,527350,527359,527367,527358,527367,527359,527330,527367,527333,527351,527333,527353,527351,527345,527380,527348,527361,527351,527357,527356,527348,527334,527363,527362,527359,527351,527353,527367,527352,527351,527349,527369,527341,527366,527353,527352,527356,527344,527341,527358,527366,527332,527354,527373,527373,527349,527374,527367,527350,527362,527338,527347,527362,527351,527371,527348,527356,527358,527343,527345,527347,527361,527343,527346,527354,527343,527366,527360,527361,527354,527357,527366,527348,527351,527358,527350,527350,527355,527345,527365,527347,527354,527335,527370,527384,527340,527345,527363,527349,527333,527351,527358,527350,527357,527338,527364,527345,527344,527361,527349,527339,527351,527356,527345,527343,527351,527349,527355,527347,527359,527352,527358,527361,527344,527356,527370,527356,527352,527365,527348,527356,527347,527363,527359,527353,527351,527340,527357,527346,527347,527339,527378,527353,527350,527365,527365,527369,527347,527352,527362,527352,527331,527361,527361,527352,527360,527355,527359,527364,527343,527340,527356,527360,527336,527351,527339,527380,527355,527355,527351,527351,527362,527331,527357,527353,527352,527343,527353,527373,527351,527355,527367,527355,527356,527356,527350,527362,527358,527359,527347,527354,527340,527357,527346,527355,527350,527346,527375,527354,527354,527343,527357,527321,527336,527350,527334,527350,527353,527348,527349,527371,527354,527356,527356,527359,527374,527338,527349,527375,527345,527351,527354,527352,527354,527357,527364,527363,527356,527367,527328,527355,527356,527356,527337,527360,527374,527336,527346,527367,527344,527347,527356,527343,527336,527369,527350,527350,527344,527352,527364,527362,527356,527350,527365,527362,527345,527356,527349,527375,527354,527350,527371,527377,527359,527337,527365,527358,527343,527363,527350,527358,527347,527339,527351,527356,527360,527352,527356,527356,527365,527353,527350,527344,527337,527355,527343,527361,527349,527348,527353,527375,527356,527343,527356,527360,527380,527348,527357,527368,527331,527361,527368,527369,527342,527367,527336,527378,527334,527343,527337,527367,527344,527352,527352,527381,527355,527344,527354,527370,527342,527329,527351,527367,527331,527358,527366,527360,527352,527375,527358,527369,527351,527362,527366,527349,527366,527335,527360,527357,527348,527353,527357,527361,527370,527328,527369,527357,527350,527368,527337,527348,527352,527358,527342,527363,527348,527367,527355,527359,527356,527357,527347,527340,527369,527357,527354,527368,527346,527357,527360,527350,527341,527348,527362,527353,527348,527333,527340,527364,527349,527350,527353,527362,527366,527348,527356,527375,527347,527361,527345,527352,527346,527346,527369,527358,527351,527361,527344,527352,527362,527351,527359,527344,527346,527377,527350,527344,527345,527347,527358,527352,527338,527337,527366,527368,527353,527344,527358,527380,527346,527339,527363,527371,527339,527353,527379,527367,527336,527356,527360,527348,527347,527361,527346,527358,527372,527351,527344,527376,527351,527362,527357,527352,527340,527367,527360,527347,527343,527352,527354,527350,527347,527348,527343,527363,527357,527352,527356,527346,527352,527335,527371,527359,527352,527335,527356,527386,527347,527346,527368,527361,527349,527351,527350,527344,527367,527360,527342,527355,527354,527346,527365,527347,527356,527352,527367,527361,527349,527350,527355,527341,527340,527355,527364,527341,527354,527358,527348,527358,527348,527351,527344,527361,527338,527350,527341,527346,527329,527363,527347,527341,527351,527346,527353,527355,527346,527361,527349,527365,527354,527361,527349,527353,527350,527362,527363,527351,527347,527365,527357,527342,527344,527363,527344,527341,527340,527346,527356,527360,527333,527340,527358,527364,527338,527335,527348,527346,527339,527340,527335,527348,527350,527356,527328,527351,527355,527362,527343,527371,527347,527344,527367,527367,527345,527348,527354,527359,527344,527346,527356,527368,527342,527357,527354,527372,527354,527362,527344,527369,527342,527334,527357,527364,527320,527337,527362,527361,527332,527345,527355,527359,527359,527341,527342,527357,527366,527362,527342,527355,527362,527359,527363,527346,527352,527356,527363,527350,527344,527354,527367,527361,527346,527361,527371,527354,527347,527352,527366,527342,527366,527344,527362,527363,527360,527354,527341,527392,527345,527352,527361,527354,527374,527342,527344,527347,527356,527342,527350,527345,527350,527355,527363,527349,527346,527351,527359,527350,527347,527350,527358,527347,527341,527361,527354,527360,527338,527354,527358,527366,527352,527345,527384,527369,527342,527351,527370,527380,527335,527362,527364,527350,527349,527346,527361,527354,527353,527373,527340,527355,527353,527350,527352,527335,527348,527343,527356,527363,527331,527355,527346,527360,527362,527351,527347,527347,527354,527364,527337,527369,527350,527354,527350,527386,527341,527372,527353,527370,527347,527362,527356,527367,527345,527344,527350,527370,527362,527336,527360,527355,527352,527342,527359,527348,527359,527362,527360,527357,527349,527355,527366,527394,527340,527349,527338,527374,527347,527353,527346,527356,527358,527363,527344,527361,527371,527342,527361,527375,527359,527359,527348,527358,527349,527351,527346,527367,527352,527357,527344,527349,527367,527350,527354,527348,527345,527360,527350,527345,527340,527351,527373,527347,527357,527344,527353,527373,527371,527361,527338,527371,527366,527374,527358,527377,527351,527344,527359,527379,527350,527353,527338,527367,527354,527349,527339,527360,527366,527359,527336,527353,527352,527367,527359,527354,527342,527349,527354,527356,527349,527351,527362,527356,527339,527364,527343,527355,527344,527354,527354,527369,527345,527350,527355,527364,527358,527356,527355,527383,527331,527353,527356,527381,527344,527343,527351,527382,527364,527345,527346,527374,527369,527351,527359,527357,527345,527345,527350,527359,527365,527353,527341,527337,527367,527359,527347,527347,527351,527358,527346,527354,527343,527375,527356,527357,527344,527353,527344,527366,527342,527348,527351,527360,527348,527342,527349,527372,527362,527356,527375,527351,527348,527371,527362,527352,527367,527345,527343,527361,527359,527358,527354,527350,527363,527353,527357,527364,527370,527349,527361,527347,527355,527359,527358,527344,527356,527351,527356,527346,527354,527350,527347,527357,527345,527363,527349,527371,527359,527355,527342,527357,527360,527355,527340,527344,527345,527366,527347,527354,527344,527341,527370,527366,527349,527350,527347,527356,527354,527345,527350,527341,527330,527354,527339,527364,527345,527351,527353,527374,527349,527346,527352,527360,527363,527369,527338,527347,527368,527371,527338,527352,527344,527363,527357,527355,527348,527346,527363,527347,527362,527349,527342,527357,527356,527355,527351,527353,527358,527355,527348,527341,527333,527363,527349,527353,527319,527341,527343,527367,527345,527343,527350,527347,527360,527342,527348,527354,527353,527346,527346,527361,527346,527356,527362,527346,527354,527367,527340,527346,527359,527364,527336,527355,527350,527357,527347,527347,527355,527354,527366,527356,527345,527359,527348,527352,527336,527372,527362,527342,527339,527339,527368,527365,527372,527351,527347,527366,527351,527346,527343,527369,527341,527346,527347,527350,527349,527362,527346,527351,527365,527344,527364,527344,527348,527351,527366,527343,527371,527361,527364,527349,527351,527364,527355,527354,527346,527363,527343,527359,527337,527354,527349,527360,527341,527345,527358,527356,527361,527350,527355,527359,527354,527366,527367,527351,527352,527358,527358,527356,527348,527356,527361,527365,527362,527355,527346,527356,527373,527343,527359,527360,527377,527354,527375,527355,527342,527348,527348,527348,527352,527351,527355,527339,527354,527349,527339,527363,527371,527349,527345,527339,527350,527357,527375,527372,527329,527347,527352,527343,527356,527363,527342,527352,527354,527352,527366,527350,527358,527348,527367,527358,527334,527360,527366,527391,527347,527353,527348,527359,527367,527362,527361,527338,527356,527351,527358,527363,527338,527343,527332,527362,527369,527355,527355,527349,527359,527355,527349,527355,527352,527368,527358,527344,527347,527338,527359,527347,527338,527350,527353,527351,527331,527355,527384,527360,527340,527362,527358,527384,527339,527355,527347,527374,527340,527357,527352,527364,527359,527337,527368,527348,527363,527338,527367,527361,527355,527354,527341,527348,527359,527356,527347,527354,527359,527343,527360,527340,527351,527355,527356,527348,527330,527361,527365,527347,527349,527376,527395,527352,527343,527345,527362,527383,527384,527338,527353,527363,527368,527341,527352,527363,527353,527347,527363,527355,527349,527355,527349,527354,527344,527360,527356,527348,527356,527372,527345,527368,527344,527343,527361,527347,527351,527349,527377,527343,527348,527348,527363,527366,527340,527372,527340,527362,527334,527370,527330,527367,527382,527350,527351,527359,527370,527352,527375,527341,527353,527357,527352,527363,527344,527355,527367,527359,527364,527357,527369,527349,527347,527368,527358,527369,527360,527349,527359,527356,527357,527344,527350,527368,527346,527345,527350,527343,527363,527345,527345,527368,527342,527360,527351,527346,527355,527355,527368,527349,527353,527355,527347,527351,527359,527357,527358,527343,527349,527350,527345,527349,527360,527347,527357,527351,527351,527343,527378,527344,527359,527354,527346,527368,527337,527358,527350,527373,527344,527347,527334,527359,527380,527375,527343,527350,527371,527354,527370,527353,527343,527338,527360,527352,527366,527365,527351,527341,527345,527362,527372,527351,527355,527348,527357,527356,527357,527340,527370,527361,527338,527350,527357,527329,527348,527354,527362,527345,527368,527362,527362,527356,527355,527352,527351,527359,527386,527352,527360,527364,527347,527342,527345,527350,527367,527371,527366,527354,527344,527358,527365,527369,527339,527353,527344,527354,527352,527349,527374,527344,527357,527358,527362,527358,527352,527363,527357,527363,527361,527359,527351,527352,527359,527357,527342,527353,527358,527340,527374,527351,527363,527349,527358,527345,527375,527353,527359,527348,527357,527350,527351,527364,527358,527354,527332,527352,527353,527352,527393,527380,527348,527349,527350,527350,527348,527372,527374,527343,527369,527354,527354,527358,527355,527346,527349,527366,527355,527343,527358,527349,527362,527349,527348,527346,527348,527351,527368,527348,527355,527376,527352,527361,527351,527380,527351,527358,527354,527364,527360,527367,527361,527349,527357,527360,527351,527338,527358,527359,527346,527359,527361,527356,527361,527357,527346,527351,527333,527359,527355,527352,527363,527352,527349,527361,527360,527344,527360,527351,527349,527366,527369,527372,527357,527324,527362,527360,527351,527344,527357,527355,527346,527355,527357,527354,527348,527349,527357,527354,527361,527344,527345,527370,527348,527348,527348,527359,527345,527347,527350,527353,527360,527359,527368,527339,527352,527349,527354,527346,527369,527362,527348,527358,527357,527348,527354,527340,527361,527348,527355,527365,527353,527340,527363,527353,527345,527349,527356,527358,527359,527343,527337,527349,527371,527359,527358,527352,527353,527354,527341,527375,527357,527351,527347,527368,527364,527363,527348,527355,527339,527353,527356,527367,527354,527366,527345,527343,527354,527352,527378,527364,527355,527356,527354,527354,527358,527334,527361,527351,527334,527360,527375,527362,527350,527357,527338,527357,527359,527359,527344,527370,527348,527351,527348,527353,527350,527351,527359,527353,527335,527346,527352,527361,527353,527345,527357,527368,527335,527356,527360,527370,527348,527346,527354,527360,527352,527354,527363,527357,527342,527339,527361,527366,527362,527345,527350,527351,527362,527366,527356,527360,527334,527353,527345,527375,527340,527354,527358,527352,527351,527369,527352,527341,527363,527340,527349,527353,527358,527360,527371,527372,527361,527338,527349,527350,527357,527351,527366,527359,527369,527350,527358,527351,527362,527334,527355,527362,527371,527342,527362,527344,527361,527350,527343,527355,527352,527354,527359,527353,527335,527346,527350,527360,527350,527359,527352,527353,527343,527362,527357,527360,527343,527354,527358,527370,527364,527339,527351,527359,527353,527346,527355,527344,527365,527342,527353,527358,527348,527356,527364,527369,527357,527357,527339,527360,527347,527364,527355,527362,527360,527365,527366,527359,527356,527333,527357,527366,527359,527359,527356,527375,527347,527342,527342,527350,527362,527337,527367,527342,527352,527357,527357,527361,527350,527342,527342,527355,527362,527352,527350,527370,527344,527358,527348,527356,527348,527341,527358,527351,527352,527345,527355,527364,527356,527351,527347,527358,527354,527352,527359,527374,527349,527355,527355,527364,527350,527339,527364,527363,527362,527340,527360,527352,527372,527345,527351,527342,527349,527352,527345,527367,527351,527364,527346,527357,527348,527340,527353,527359,527358,527351,527355,527341,527355,527354,527358,527345,527338,527357,527363,527359,527357,527355,527347,527349,527350,527349,527355,527364,527343,527327,527368,527362,527364,527364,527349,527349,527356,527343,527372,527359,527353,527349,527344,527347,527360,527360,527350,527348,527342,527365,527342,527369,527359,527344,527356,527347,527348,527352,527359,527356,527352,527351,527363,527358,527359,527352,527361,527361,527334,527347,527369,527357,527369,527350,527355,527344,527343,527344,527360,527357,527346,527348,527349,527371,527338,527346,527350,527352,527343,527361,527355,527361,527356,527344,527336,527365,527354,527360,527360,527360,527352,527345,527360,527365,527361,527341,527356,527352,527352,527346,527356,527355,527358,527335,527346,527352,527365,527348,527366,527348,527363,527341,527356,527351,527351,527370,527354,527356,527347,527357,527346,527361,527358,527352,527357,527346,527369,527357,527363,527352,527360,527347,527363,527372,527357,527339,527352,527360,527352,527354,527349,527355,527371,527342,527332,527344,527371,527358,527358,527342,527349,527356,527337,527344,527365,527360,527341,527345,527342,527358,527349,527357,527352,527360,527343,527349,527348,527341,527365,527360,527350,527357,527365,527345,527363,527351,527363,527358,527347,527354,527357,527367,527368,527342,527355,527358,527353,527357,527341,527355,527365,527350,527344,527362,527357,527350,527343,527371,527355,527358,527351,527350,527356,527334,527347,527351,527361,527355,527358,527342,527358,527346,527360,527360,527350,527360,527360,527362,527347,527354,527354,527358,527361,527343,527354,527346,527344,527350,527357,527376,527353,527342,527335,527353,527358,527334,527349,527360,527390,527389,527346,527359,527353,527349,527341,527367,527367,527353,527366,527364,527376,527350,527343,527343,527351,527337,527351,527362,527358,527353,527360,527366,527355,527349,527348,527352,527355,527345,527359,527370,527372,527356,527343,527348,527345,527360,527368,527357,527360,527348,527337,527359,527369,527356,527350,527358,527358,527345,527371,527369,527354,527357,527344,527363,527352,527329,527349,527371,527348,527348,527364,527354,527367,527346,527347,527344,527356,527350,527376,527390,527349,527363,527343,527355,527343,527356,527370,527350,527359,527369,527346,527359,527350,527350,527346,527348,527333,527373,527363,527365,527364,527352,527359,527353,527353,527340,527354,527360,527370,527353,527364,527360,527362,527344,527356,527350,527362,527351,527364,527362,527350,527355,527349,527377,527352,527348,527362,527355,527357,527345,527355,527363,527359,527360,527342,527353,527358,527354,527360,527366,527346,527370,527352,527367,527353,527356,527367,527350,527337,527352,527358,527364,527375,527338,527355,527361,527341,527343,527364,527359,527343,527364,527348,527358,527361,527349,527334,527348,527369,527344,527356,527363,527362,527353,527340,527351,527362,527361,527353,527366,527358,527353,527367,527348,527351,527353,527345,527359,527352,527362,527356,527367,527353,527341,527360,527347,527367,527340,527358,527363,527340,527361,527361,527357,527346,527350,527362,527343,527369,527357,527350,527368,527381,527344,527340,527360,527343,527362,527352,527373,527347,527353,527368,527349,527344,527358,527349,527352,527353,527354,527351,527358,527363,527352,527351,527357,527364,527349,527352,527358,527344,527345,527374,527358,527358,527334,527356,527365,527346,527351,527367,527354,527363,527354,527356,527356,527360,527354,527357,527354,527348,527344,527353,527368,527359,527360,527339,527362,527349,527355,527345,527351,527358,527346,527361,527349,527352,527359,527362,527353,527353,527357,527345,527349,527356,527361,527350,527359,527362,527356,527331,527359,527354,527343,527352,527341,527351,527349,527363,527352,527353,527356,527355,527341,527354,527358,527359,527355,527398,527380,527354,527359,527370,527347,527341,527373,527357,527343,527403,527393,527358,527344,527355,527359,527348,527356,527361,527340,527348,527371,527345,527355,527362,527366,527344,527344,527349,527344,527358,527370,527351,527377,527353,527347,527351,527350,527357,527357,527346,527350,527365,527365,527362,527339,527347,527361,527355,527355,527354,527372,527359,527343,527361,527347,527353,527344,527353,527345,527357,527360,527337,527355,527350,527350,527341,527349,527361,527349,527353,527347,527347,527358,527348,527357,527354,527364,527344,527353,527363,527368,527349,527365,527370,527337,527342,527340,527352,527357,527363,527375,527335,527361,527365,527353,527349,527332,527345,527357,527404,527410,527369,527372,527359,527346,527347,527352,527342,527356,527398,527408,527346,527361,527352,527358,527353,527349,527340,527341,527372,527354,527360,527346,527356,527353,527336,527352,527362,527365,527355,527343,527358,527342,527363,527372,527341,527349,527354,527358,527342,527356,527348,527372,527350,527364,527354,527333,527354,527346,527362,527364,527352,527345,527358,527372,527347,527352,527340,527355,527353,527356,527359,527372,527346,527347,527350,527361,527336,527361,527363,527355,527357,527355,527350,527360,527352,527359,527349,527349,527361,527363,527369,527362,527353,527349,527359,527359,527336,527350,527358,527351,527356,527352,527360,527364,527341,527359,527360,527351,527354,527356,527343,527380,527360,527357,527352,527366,527348,527338,527361,527358,527341,527367,527366,527352,527351,527350,527354,527352,527347,527360,527342,527373,527350,527351,527341,527348,527344,527358,527349,527368,527348,527362,527373,527359,527336,527351,527358,527348,527345,527360,527354,527343,527371,527367,527348,527359,527345,527353,527346,527348,527345,527343,527368,527366,527343,527342,527363,527362,527344,527358,527358,527374,527345,527342,527367,527354,527358,527349,527355,527369,527361,527355,527356,527358,527359,527338,527345,527349,527354,527356,527343,527354,527355,527359,527356,527349,527342,527346,527363,527348,527344,527350,527357,527341,527358,527349,527351,527357,527362,527358,527357,527357,527356,527342,527364,527358,527337,527347,527368,527386,527356,527341,527359,527346,527363,527348,527339,527357,527357,527355,527352,527357,527349,527344,527347,527374,527347,527348,527363,527346,527338,527368,527372,527355,527355,527368,527352,527354,527349,527373,527367,527356,527364,527365,527370,527364,527342,527357,527361,527374,527356,527345,527374,527359,527350,527343,527363,527357,527341,527351,527355,527355,527361,527357,527334,527364,527351,527341,527361,527351,527354,527336,527360,527350,527358,527342,527362,527342,527342,527350,527369,527355,527343,527333,527362,527335,527355,527361,527367,527354,527349,527349,527355,527357,527346,527340,527355,527349,527344,527354,527349,527357,527356,527344,527350,527348,527350,527350,527379,527350,527352,527354,527347,527369,527362,527335,527346,527353,527357,527375,527366,527347,527367,527343,527357,527346,527354,527338,527357,527355,527354,527358,527366,527345,527360,527340,527350,527359,527359,527359,527359,527371,527392,527357,527364,527349,527353,527350,527354,527362,527352,527363,527376,527373,527352,527358,527347,527354,527345,527355,527355,527357,527361,527341,527356,527357,527355,527340,527343,527369,527353,527335,527365,527359,527359,527338,527349,527353,527346,527356,527349,527356,527368,527357,527342,527347,527343,527352,527350,527354,527354,527363,527348,527349,527360,527344,527354,527350,527365,527357,527368,527363,527343,527340,527354,527358,527348,527337,527370,527366,527348,527351,527364,527352,527345,527353,527336,527369,527355,527343,527350,527363,527366,527347,527354,527353,527370,527362,527350,527341,527349,527366,527346,527366,527360,527355,527346,527339,527364,527348,527353,527360,527369,527347,527369,527361,527344,527346,527344,527366,527344,527350,527374,527369,527354,527348,527364,527368,527355,527342,527355,527350,527350,527342,527354,527358,527358,527348,527348,527371,527348,527347,527358,527352,527360,527348,527343,527350,527346,527360,527352,527358,527351,527361,527347,527361,527353,527345,527361,527350,527342,527362,527341,527358,527349,527361,527350,527369,527342,527341,527362,527357,527345,527352,527355,527349,527349,527354,527358,527356,527355,527366,527361,527362,527366,527343,527372,527363,527349,527347,527365,527373,527361,527341,527369,527354,527355,527349,527362,527355,527358,527351,527368,527360,527352,527342,527340,527365,527353,527359,527350,527365,527358,527349,527348,527356,527337,527349,527371,527340,527351,527355,527347,527350,527363,527353,527362,527352,527353,527350,527371,527353,527348,527342,527364,527354,527346,527332,527355,527383,527339,527340,527351,527375,527353,527341,527354,527354,527347,527341,527350,527350,527353,527346,527353,527357,527368,527354,527350,527350,527352,527352,527339,527344,527351,527352,527355,527352,527354,527375,527378,527350,527353,527350,527353,527338,527360,527358,527365,527380,527361,527352,527371,527361,527345,527353,527349,527367,527340,527361,527354,527361,527356,527345,527348,527365,527349,527350,527355,527370,527346,527362,527354,527347,527347,527358,527344,527348,527364,527364,527361,527358,527369,527337,527365,527351,527343,527353,527364,527360,527351,527351,527365,527360,527340,527344,527351,527364,527340,527355,527362,527357,527354,527360,527348,527363,527341,527357,527359,527347,527351,527341,527352,527354,527345,527355,527357,527362,527338,527358,527369,527372,527358,527346,527353,527339,527346,527340,527366,527363,527342,527354,527364,527374,527356,527361,527341,527345,527349,527341,527363,527351,527357,527357,527353,527361,527344,527343,527360,527353,527357,527352,527339,527357,527346,527364,527355,527349,527339,527371,527370,527351,527345,527361,527344,527359,527336,527358,527350,527371,527358,527363,527373,527364,527353,527361,527347,527362,527342,527354,527356,527370,527345,527359,527353,527376,527367,527343,527349,527345,527348,527351,527348,527350,527350,527363,527357,527363,527351,527341,527352,527356,527363,527360,527346,527348,527355,527341,527366,527370,527347,527343,527370,527362,527346,527356,527352,527372,527346,527358,527351,527359,527356,527364,527358,527366,527360,527356,527357,527352,527340,527347,527372,527352,527336,527350,527353,527346,527369,527367,527343,527357,527356,527353,527338,527363,527349,527352,527354,527364,527352,527342,527371,527362,527359,527341,527351,527351,527366,527334,527354,527364,527360,527357,527347,527368,527359,527340,527348,527366,527345,527345,527359,527344,527363,527356,527345,527350,527345,527360,527356,527352,527361,527347,527352,527348,527349,527343,527348,527361,527343,527345,527360,527359,527358,527347,527350,527364,527357,527347,527341,527364,527354,527341,527349,527370,527362,527351,527357,527359,527380,527347,527353,527353,527357,527359,527360,527353,527345,527352,527344,527349,527355,527363,527343,527355,527361,527357,527359,527365,527350,527344,527343,527332,527363,527360,527354,527350,527410,527399,527355,527363,527355,527353,527343,527367,527346,527352,527401,527395,527347,527374,527379,527351,527346,527344,527362,527352,527353,527357,527351,527363,527352,527343,527350,527363,527355,527352,527362,527360,527354,527348,527366,527364,527335,527349,527353,527350,527366,527363,527346,527378,527367,527346,527359,527339,527363,527343,527369,527359,527344,527353,527356,527363,527354,527341,527364,527337,527359,527365,527335,527350,527353,527360,527359,527350,527351,527347,527348,527367,527358,527352,527351,527359,527353,527350,527360,527356,527331,527342,527346,527362,527361,527349,527343,527349,527370,527350,527351,527363,527360,527348,527338,527356,527361,527352,527353,527344,527400,527400,527360,527356,527357,527367,527346,527345,527350,527356,527389,527381,527344,527358,527365,527370,527342,527354,527360,527355,527354,527342,527353,527355,527356,527345,527348,527350,527359,527342,527387,527392,527352,527363,527361,527362,527340,527349,527361,527344,527362,527380,527351,527367,527384,527367,527352,527347,527365,527358,527349,527353,527352,527346,527367,527370,527352,527340,527353,527355,527345,527346,527360,527354,527358,527365,527348,527362,527365,527333,527360,527347,527348,527349,527354,527358,527349,527354,527364,527360,527368,527340,527359,527363,527344,527343,527351,527359,527356,527343,527356,527353,527353,527359,527363,527355,527349,527369,527359,527341,527351,527337,527353,527359,527359,527357,527356,527359,527353,527356,527358,527362,527346,527350,527343,527338,527356,527365,527348,527337,527365,527370,527364,527352,527358,527352,527349,527344,527355,527354,527357,527355,527351,527375,527366,527357,527356,527360,527366,527353,527331,527349,527354,527361,527355,527356,527361,527372,527374,527345,527362,527365,527359,527343,527338,527353,527349,527362,527355,527356,527354,527352,527354,527353,527353,527366,527347,527346,527351,527364,527348,527343,527358,527352,527370,527345,527359,527356,527355,527352,527348,527341,527369,527347,527347,527359,527361,527362,527337,527348,527353,527350,527365,527328,527349,527357,527348,527346,527366,527363,527364,527364,527368,527356,527355,527349,527357,527337,527356,527352,527364,527368,527347,527362,527361,527378,527356,527350,527356,527341,527357,527346,527354,527354,527350,527352,527355,527359,527370,527347,527357,527355,527344,527363,527353,527360,527343,527354,527364,527356,527345,527351,527358,527351,527357,527351,527351,527360,527346,527357,527360,527364,527337,527357,527375,527353,527351,527347,527363,527348,527350,527341,527355,527360,527356,527352,527349,527360,527369,527345,527365,527341,527354,527340,527347,527353,527347,527368,527348,527361,527357,527349,527357,527347,527361,527361,527342,527339,527352,527356,527375,527356,527341,527347,527358,527352,527352,527353,527356,527357,527352,527366,527362,527368,527355,527364,527355,527364,527355,527348,527366,527362,527351,527341,527354,527354,527352,527354,527365,527356,527350,527361,527356,527363,527367,527356,527347,527342,527347,527353,527370,527334,527365,527373,527386,527361,527340,527361,527349,527366,527356,527352,527356,527355,527360,527390,527361,527354,527350,527355,527357,527362,527355,527353,527355,527345,527359,527347,527361,527360,527357,527352,527350,527369,527340,527355,527359,527352,527336,527349,527351,527358,527353,527364,527362,527365,527346,527344,527361,527350,527352,527339,527358,527356,527343,527352,527355,527361,527349,527361,527356,527349,527360,527348,527356,527354,527343,527342,527352,527365,527365,527356,527333,527363,527357,527362,527358,527353,527353,527338,527373,527370,527349,527347,527369,527352,527342,527356,527357,527359,527345,527353,527350,527359,527352,527362,527359,527342,527348,527352,527354,527359,527351,527356,527358,527359,527347,527359,527353,527359,527358,527358,527355,527371,527375,527361,527363,527351,527357,527346,527358,527370,527354,527348,527369,527367,527346,527352,527348,527361,527352,527354,527363,527364,527353,527352,527359,527356,527362,527353,527355,527361,527335,527351,527355,527356,527376,527344,527367,527355,527344,527361,527358,527356,527346,527362,527356,527352,527360,527354,527350,527353,527363,527353,527359,527362,527357,527357,527357,527348,527342,527345,527366,527352,527356,527354,527360,527349,527358,527347,527356,527363,527345,527346,527352,527355,527357,527347,527355,527354,527354,527345,527360,527368,527348,527359,527349,527345,527344,527360,527366,527365,527339,527358,527352,527359,527356,527364,527347,527340,527354,527349,527350,527349,527343,527368,527352,527352,527368,527359,527391,527357,527352,527343,527356,527355,527348,527344,527363,527354,527351,527364,527355,527371,527360,527354,527359,};
ll gbc(ll l,ll r){
if (l>r) return 0;
memset(t,0,sizeof(t));
ll ans=0;
for (ll i=1;i<=n;i++){
for (ll j=r/num[i]*num[i];j>=l;j-=num[i]) t[j-l]=1;
}
for (ll i=l;i<=r;i++) ans+=t[i-l];
return ans;
}
inline void dfs(ll now){
if (now>1e10) return ;
if (now) num[++n]=now;
dfs(now*10+6),dfs(now*10+8);
}
signed main(){
cin>>A>>B;
dfs(0);
for (ll i=1;i*lb<=1e10;i++) sum[i]=sum[i-1]+biao[i];
printf("%lld",sum[B/lb]-sum[A/lb]-gbc(A/lb*lb+1,A)+gbc(B/lb*lb+1,B));
return 0;
}