Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya calls a mask of a positive integer n the number that is obtained after successive writing of all lucky digits of number n from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number.Petya has two numbers — an arbitrary integer a and a lucky number b. Help him find the minimum number c (c > a) such that the mask of number c equals b.

The only line contains two integers a and b (1 ≤ a, b ≤ 105). It is guaranteed that number b is lucky.

In the only line print a single number — the number c that is sought by Petya.

var
i,a,b:longint;
aa,bb,w:string;
 begin
  readln(a,b);
  a:=a+1;
  str(b,bb);
  while true do
    begin
     str(a,aa);
     w:='';
     for i:=1 to length(aa) do
       if aa[i] in ['4','7'] then w:=w+aa[i];

     if w=bb then break;
     a:=a+1;
    end;
  writeln(a);
 end.

var a,b,c,i,k,aa:longint;
    x:array[1..10]of integer;

begin
 read(a,b);
 if a<b then write(b) else begin
 while true do
  begin
   inc(a);
   k:=0;
   c:=0;
   aa:=a;
   while a>0 do
    begin
     if a mod 10= 4 then begin inc(k);x[k]:=4; end;
     if a mod 10= 7 then begin inc(k);x[k]:=7; end;
     a:=a div 10;
    end;
   for i:=k downto 1 do
    c:=c*10+x[i];
   if c=b then begin writeln(aa);break; end;
   a:=aa;

  end;
 end;
end.

var a,b,c,i:longint;
function mask(a:longint):longint; var c,n,f:longint; p:byte;
begin n:=a; c:=0; f:=0;
repeat p:=n mod 10; if (p=4) or (p=7) then
begin if f=0 then f:=1 else f:=f*10; c:=c+f*p; end; n:=n div 10; until n=0;
mask:=c; end;
begin readln(a,b);
if b>a then begin write(b); exit; end;
i:=a; repeat inc(i); if mask(i)=b then begin writeln(i); exit; end;
until i>1000000;
end.

uses sysutils;
var a, b, c, i: integer;

function mask(n: integer): integer;
var i: integer;
    s, s2: string;
begin
  s := inttostr(n);
  s2 := '';
  for i := 1 to length(s) do
    if (s[i] = '4') or (s[i] = '7') then
      s2 := s2 + s[i];
  if length(s2) <> 0 then
    result := strtoint(s2)
  else
    result := 0;
end;

begin
  //assign(input, 'input.txt'); reset(input);
  //assign(output, 'output.txt'); rewrite(output);
  readln(a, b);
  c := a + 1;

  while (mask(c) <> b) do begin
    inc(c);

  end;

  writeln(c);

end.

program CF_104_2_B;

{$APPTYPE CONSOLE}
{$R-,Q-}

uses
  SysUtils;

var
	a, k, c, b, i: integer;
	a_s, b_s, n_s : string;
begin
	readln(a, b);
	c:=0;
  a:=a+1;
  N_s:='';
	b_s := IntToStr(b);
 	while c=0 do begin
		a_s := IntToStr(a);
    for i:=1 to length (a_s) do
      begin
        if (a_s[i]=('4')) or (a_s[i]=('7')) then n_s:=n_s+a_s[i];
      end;
    if n_s=b_s then
			begin
        inc(c);
        write(a_s);
			end
		else begin inc(a); n_s:=(''); end
	end;
	readln;
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var
  a,b,i:integer;

  function mask(x:integer):integer;
  var
  k,i,code:integer;
  s,ans:string;
  begin
  str(x,s);
  ans:='0';
   for i:=1 to length(s) do
   begin
    if (s[i]='4')or(s[i]='7') then ans:=ans+s[i];
   end;
   val(ans,k,code);
   mask:=k;
  end;

begin
readln(a,b);
for i:=a+1 to 177777 do
begin
 if (mask(i)=b) then begin writeln(i); readln; halt; end;
end;

end.

var n,i,j,k1,m:longint;
    s,k,s1:ansistring;
begin
readln(n,m);
while true do
begin
   inc(n);
   str(n,k);
   k1:=length(k);
   for i:=1 to k1 do
      if (k[i]='4') or (k[i]='7') then s1:=s1+k[i];
   val(s1,j,k1);
   if j=m then begin writeln(n); halt; end;
   s1:='';
   k:='';

end;
end.

var a,b,c:dword;
function kt:boolean;
var s:string[6]; i:byte; tg:dword=0;
begin
        str(c,s);
        for i:=1 to length(s) do
        if s[i] in ['4','7'] then tg:=tg*10+ord(s[i])-48;
        if tg=b then kt:=true
        else kt:=false
end;
begin
        read(a,b);
        c:=b;
        while c<=a do
        repeat inc(c)
        until kt;
        write(c)
end.

{$APPTYPE CONSOLE}
{$R+,Q+,I+}

uses
  SysUtils;

{function Happy(a:integer):Boolean;
var
   i:integer;
begin
  Happy:=False;
  i:=a;
  while i>0 do begin
    if (i mod 10 <>4) and (i mod 10 <> 7) then Exit;
    i:=i div 10;
  end;
  Happy:=True;
end;}

function Mask(a:Integer):Integer;
var
  i:Byte;
  c:string;
begin
  c:='';
  for i:=1 to Length(IntToStr(a)) do begin
     if (Copy(IntToStr(a),i,1)='4') or (Copy(IntToStr(a),i,1)='7') then c:=c+Copy(IntToStr(a),i,1);
  end;
  if c='' then Mask:=0 else Mask:=StrToInt(c);
end;

var
  a,b,c:integer;
begin
  read(a,b);
  repeat
    inc(a);
    c:=Mask(a);
  until c=b;
  write(a);
  Readln;
  Readln;
end.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q+,R+,S-,T-,U-,V+,W-,X+,Y+,Z1}
uses sysutils;
var a,b,c:LongInt;
    s:string;
function mask(x:LongInt):string;
var s:string;
    i:Integer;
begin
  s:=inttostr(x);
  result:='';
  for i:=1 to Length(s) do
  begin
    if s[i] in ['4','7']
    then result:=result+s[i];
  end;
end;
begin
   //reset(input,'input.txt');
   //rewrite(output,'output.txt');
   Readln(a,b);
   s:=inttostr(b);
   c:=a+1;
   while mask(c)<>s do
   Inc(c);
   Writeln(c);
end.

{lai troi cho conn dung}
const
  fi='input.inp';
var
  a,b : longint;
{---------------------------------------------}
procedure mo;
begin
  //assign(input,fi);reset(input);
  readln(a,b);
  a :=a + 1;
end;
{---------------------------------------------}
procedure xuli;
var
  tmp : string;
  s1,s2 : string;
  i,j : longint;
begin
  repeat
    if a >= b then
      begin
        str(a,s1);
        str(b,s2);
        j := 1;
        {for i :=1 to length(s1) do
          begin
            if s1[i] = s2[j] then inc(j);
            if j =  length(s2) + 1 then
              begin
                writeln(s1);
                exit;
              end;
          end;   }
        tmp :='';
        for i := 1 to length(s1) do
          if (s1[i] = '4') or (s1[i] = '7') then tmp := tmp + s1[i];
        if tmp = s2 then
          begin
            writeln(s1);
            exit;
          end;
        a :=a + 1;
      end
    else a :=a + 1;
  until false;
end;
{---------------------------------------------}
begin
  mo;
  xuli;
end.

Program Problem_B;
uses SysUtils;
var k,i,n,j,z : longint;
    f : boolean;
    s : string;
begin
 readln(k,n);
 i := k;
 while not(f) do
  begin
   inc(i);
   z := 0;
   s := IntToStr(i);
   for j := 1 to length(s) do
    begin
     if (s[j] = '7') or (s[j] = '4') then
      z := z*10 + StrToInt(s[j]);
    end;
   if n = z then f := true;
  end;
 writeln(i);
end.

program task_2;
{$APPTYPE CONSOLE}
uses SysUtils;
var a,b:integer;
    s1,s2:string;

function mask(t:string):string;
var i:integer;
    tmp:string;
begin
  tmp:='';
  for i:=1 to length(t)do
    if (t[i]='4')or(t[i]='7')then
      tmp:=tmp+t[i];
  mask:=tmp;
end;

begin
  read(a,b);
  if (b>a)then begin
    write(b);
    halt;
  end;
  inc(a);
  s1:=inttostr(a);
  s2:=inttostr(b);
  while (mask(s1)<>s2)do begin
    inc(a);
    s1:=inttostr(a);
  end;
  write(s1);
end.

var y,s:string;
    a,b,x,i,c,z:longint;
begin
  read(a,b);
  for c:=a+1to 1000000do
    begin
      x:=c;
      y:='';
      str(x,s);
      for i:=1to length(s)do
        if(s[i]='4')or(s[i]='7')then y:=y+s[i];
      val(y,x,z);
      if x=b then break;
    end;
  write(c)
end.

var bb,a,b,i:longint;

function mask(i:longint):longint;
var j,s:longint;
b:array [1..100] of byte;
begin
j:=1;
while i<>0 do begin
b[j]:=i mod 10;
i:=i div 10;
inc(j);
end;
dec(j);
s:=0;
for j:=j downto 1 do
if (b[j]=4) or (b[j]=7) then s:=(s+b[j])*10;
s:=s div 10;
mask:=s;
end;

begin
read(a,b);
i:=a+1;
while mask(i)<>b do
inc(i);
write(i);
end.

Var a,b,c,i,j:longint; s,ss,g:string;

Function check:boolean;
Var q:string;i:longint;
begin

q:=''; for i:=1 to length(s) do if (s[i]='4')or(s[i]='7') then q:=q+s[i];

if q=g then check:=true else check:=false;

End;

Begin

Readln(a,b); i:=a+1; if a<b then Begin Writeln(b); halt; end;

ss:=''; While a>0 do begin ss:=char(a mod 10+48)+ss; a:=a div 10; end;
g:=''; While b>0 do begin g:=char(b mod 10+48)+g; b:=b div 10; end;

While true do begin

s:='';j:=i; While j>0 do begin s:=char(j mod 10+48)+s; j:=j div 10; end;

if check then begin Writeln(s); halt; end;

inc(i); end;

End.

var a,b,x:longint;
function mask (a1:longint):longint;
 var x1,k:longint;
 begin
 x1:=0; k:=0;
 while a1>0 do
  begin
  if (a1 mod 10=4) or (a1 mod 10=7) then x1:=(x1*10)+(a1 mod 10);
  a1:=a1 div 10;
  end;
 while x1>0 do
  begin
  k:=(k*10)+(x1 mod 10);
  x1:=x1 div 10;
  end;
 mask:=k;
 end;
begin
readln(a,b);
x:=a+1;
while mask(x)<>b do
 inc(x);
write(x);
end.

Var a,b:longint;

 procedure InputData;
 begin
 readln(a,b);
 end;

 function mask(x:longint):longint;
 var y,p,s,i:longint;
     s1:string;
 begin
 s:=0;
 str(x,s1);
 for i:=1 to length(s1) do
        if (s1[i]='4') or (s1[i]='7') then
                begin
                val(s1[i],y,p);
                s:=s*10+y;
                end;
 mask:=s;
 end;

 procedure ProcessData;
 var i:longint;
 begin
 i:=a+1;
 while true do
        begin
        if mask(i)=b then break;
        inc(i);
        end;
 writeln(i);
 end;

begin
InputData;
ProcessData;
end.

var
    a,b,i,j:longint;
    ss,te,s:string;
begin
    readln(a,b);
    str(b,ss);
        i:=a;
        while true do begin
                i:=i+1;
                te:='';
        str(i,s);
        for j:=1 to length(s) do if (s[j]='4')or(s[j]='7') then te:=te+s[j];
        if te=ss then begin
            writeln(i);
            halt;
        end;
    end;
end.

program happy_mask;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
    a,b,c:integer;

function mask(x:integer):integer;
var
    y,z,d:integer;
begin
    y:=x;
    z:=0;
    d:=10;
    while (d<=x) do d:=10*d;
    d:=d div 10;
    while (y>0) do
    begin
        if((y div d)=4) or ((y div d)=7) then
            z:=10*z+(y div d);
        y:=y mod d;
        d:=d div 10;
    end;
    mask:=z;
end;

begin
    readln(a,b);
    a:=a+1;
    c:=mask(a);
    while(c<>b) do
    begin
        inc(a);
        c:=mask(a);
    end;
    writeln(a);
end.

uses math;
var n,i,j,k,a,b:longint;
    s:string;
{
function f(n:longint):string;
begin
f:='';
while n>0 do
 begin
 f:=chr(ord('0')+n mod 10)+f;
 n:=n div 10;
 end;
end;
}
begin
read(a,b);

for j:=1+a to 999999 do
 begin

 k:=j;
 s:='';
 while k>0 do
  begin
  s:=chr(ord('0')+k mod 10)+s;
  k:=k div 10;
  end;

 k:=0;
 for i:=1 to length(s)do
 if (s[i]='4')or(s[i]='7')then k:=k*10+ord(s[i])-ord('0');

 if k=b then begin writeln(j);halt;end;
 end;
end.

var
	x, code, a, b, c, i: longint;
	s: ansistring;

begin
 //	reset(input, 'a.in');
//	rewrite(output, 'a.out');
	readln(a, b);
	for i := a + 1 to 10000000 do begin
		s := ''; c := i;
		while (c > 0) do begin
			if (c mod 10 = 4) or (c mod 10 = 7) then
                                s := chr(c mod 10 + 48) + s;
			c := c div 10;
		end;
		val(s, x, code);
        if x = b then begin
        	write(i);
        	halt;
       	end;
	end;
end.

var
 c:integer;
 s1,s,ss:string;
 j:byte;
 i:longint;
 a,b,n,k:longint;
begin
 readln(a,b);
 str(b,s1);
 for i:=a+1 to 1000000 do
 begin
  s:='';
  ss:='';
  c:=0;
  str(i,s);
  for j:=1 to length(s) do
  if (s[j]='4') or (s[j]='7') then
  insert(s[j],ss,300);
  if ss=s1 then
  begin
   writeln(s);
   halt;
  end;
 end;
end.

Uses Math;
type mass=array[0..50000,1..3] of integer;
Var n,d1,d2,c,l,k,i,a,b,z:LongInt;ch:char;m1,dp:mass;s,s1:string;
Begin
//   ReSet(input,'input.txt');
//   ReWrite(output,'output.txt');
   readln(a,b);
   if b>a
   then Begin
          writeln(b);
          halt(0);
        end;
   str(b,s);
   for i:=a+1 to a+1000001 do
      Begin
         c:=i;
         s1:='';
         while c>0 do
            Begin
               if (c mod 10) in [4,7]
               then s1:=chr(ord('0')+c mod 10)+s1;
               c:=c div 10;
            end;
         if s1=s
         then Begin
                writeln(i);
                halt(0);
              end;
      end;
End.

var
        a,b:longint;
        i,j:longint;
        bi,t:array[0..6] of longint;
function chack(n:longint):boolean;
var i,j,ti,k:longint;
begin
        k:=0;
        for i:=6 downto 1 do
        if
        (n div t[i] mod 10 =4)
        or
        (n div t[i] mod 10 =7)
        then k:=k*10+n div t[i] mod 10;
        exit(k=b);
end;
begin
        readln(a,b);
        bi[0]:=-1;
        t[1]:=1;
        for i:=2 to 6 do t[i]:=10*t[i-1];
        for i:=1 to 6 do bi[i]:=b div t[i] mod 10;
        if b>a then writeln(b)
        else
        begin
        for i:=a+1 to 200000 do
        if chack(i) then begin writeln(i);exit;end;
        end;
end.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

function pa(c: integer): integer;
var
  s1, s: string;
  i: integer;
begin
  s1 := '';
  s := inttostr(c);
  for i := 1 to length(s) do
    if (s[i] = '4') or (s[i] = '7') then
      s1 := s1 + s[i];
  if s1 = '' then
    s1 := '0';
  result := strtoint(s1);
end;

var
  a, b, c: integer;

begin
  read(a, b);
  c := a + 1;
  while pa(c) <> b do
    inc(c);
  writeln(c);
end.

program B104;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  a, b, i, min: integer;

function mask(s: string): integer;
var
  m: string;
begin
  m := '';

  while length(s) > 0 do begin
    if s[1] = '4' then
      m := m + '4';
    if s[1] = '7' then
      m := m + '7';
    delete(s, 1, 1);
  end;

  if m = '' then
    m := '0';
  mask := strtoint(m);
end;

begin
  read(a, b);
  min := maxint;

  if b > a then begin
    write(b);
    halt(0);
  end;

  for i := a + 1 to 999999 do
    if (mask(inttostr(i)) = b) then begin
      write(i);
      halt(0);
    end;

  write(min);
end.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q+,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
//{$A8,B-,C+,D-,E-,F-,G+,H+,I-,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}

program ProblemB;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

const
  inname = 'input.txt';
  outname = 'output.txt';
  maxn = 0;
  maxm = 0;
  inf = maxlongint div 2;
  eps = 0;

type
  int = longint;
  bool = boolean;
  real = extended;

var
  a, b: int;

function m(a: int): int;
var
  k, d, t: int;
begin
  d := 10000000;
  while d > a do
    d := d div 10;

  t := 0;
  while a > 0 do begin
    k := a div d;
    if (k = 4) or (k = 7) then
      t := 10 * t + k;
    a := a mod d;
    d := d div 10;
  end;

  result := t;
end;

procedure run;
begin
  read(a, b);

  inc(a);

  while m(a) <> b do
    inc(a);

  write(a);
end;

procedure openfiles;
begin
  assign(input, inname);
  assign(output, outname);
  reset(input);
  rewrite(output);
end;

procedure closefiles;
begin
  close(input);
  close(output);
end;

Begin
  //openfiles;
  run;
  //closefiles;
End.

uses sysutils;
var
  A,B,C:longint;
function getMask(a:longint):longint;
var
  s,s2:string;
  i:byte;
begin
  s:=IntToStr(a);
  s2:='';
  for i := 1 to length(s) do
    if s[i] in ['7','4']
      then
        s2:=s2+s[i];
  if s2 = ''
     then
       s2:='0';
  getMask:=StrToInt(s2);
end;
begin
  read(A,B);
  for C:=A+1 to 1000000 do
    if getMask(C)=B
      then
        break;

  writeln(C);
end.

var a,b,i,kl,x:longint;
    st,s:string;
    code:integer;
begin
  readln(a,b);
  while kl<>1 do
  begin
    inc(a);
    str(a,st);
    for i:=1 to length(st) do
      if (st[i]='4') or (st[i]='7')
      then s:=s+st[i];
    val(s,x,code);
    if x=b
    then
    begin
      writeln(a);
      break;
    end;
    s:='';
  end;
end.

var s1,s:string;
    a,b,x,i,c:longint; z:integer;
begin
readln(a,b);
for c:=a+1 to 1000000
do begin x:=c; s1:='';
str(x,s);
for i:=1 to length(s) do if (s[i]='4') or (s[i]='7') then s1:=s1+s[i];
val(s1,x,z); if x=b then break; end;
writeln(c);
end.

const
    finp='';
    fout='';
var a,KQ:string;
    x,y,i,x1,b,t:longint;
    f,g:text;
begin
    assign(f,finp); reset(f);
    assign(g,fout); rewrite(g);
    read(f,x,y);
    x1:=x;
    repeat
        inc(x);
        str(x,a);
        for i:=length(a) downto 1 do
            if (a[i]<>'4') and (a[i]<>'7') then
                delete(a,i,1);
        val(a,b,t);
    until (b=y) and (x>x1);
    str(x,KQ);
    write(g,KQ);
    close(f); close(g);
end.

var
    a,b,i:longint;

function numoff(x:longint):longint;
var
    i,ans:longint;
    tmp:string;
begin
    str(x,tmp);
    i:=1;
    while i<=length(tmp) do
    begin
        if (tmp[i]<>'4')and(tmp[i]<>'7') then delete(tmp,i,1)
        else inc(i);
    end;
    val(tmp,ans);
    exit(ans);
end;

begin
    readln(a,b);
    for i:=a+1 to 1000000 do
    if numoff(i)=b then
    begin
        writeln(i);
        halt;
    end;
end.
//By THCDUSMAN

{$APPTYPE CONSOLE}{$o-}{$r+}

uses
  SysUtils;

var
  i, a, b : integer;
  s, ans : string;

begin
  read(a, b);
  while ans <> inttostr(b) do
  begin
    inc(a);
    ans := '';
    s := inttostr(a);
    for i := 1 to length(s) do
      if (s[i] = '4') or (s[i] = '7') then
        ans := ans + s[i];
  end;
  write(a);
end.

var
    a,b,i,j:longint;
    ss,te,s:string;
begin
    readln(a,b);
    str(b,ss);
        i:=a;
        while true do begin
                i:=i+1;
                te:='';
        str(i,s);
        for j:=1 to length(s) do if (s[j]='4')or(s[j]='7') then te:=te+s[j];
        if te=ss then begin
            writeln(i);
            halt;
        end;
    end;
end.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
i,n,t,t2,k,j,a,b:Integer;
str,str1:String;
bol:Boolean = False;
begin
Readln(a,b);
for i:=a+1 to 1000000 do
begin
  str:=IntToStr(i);
  str1:='';
  for j:=1 to Length(str) do
  if (str[j]='4') or (str[j]='7') then
  str1:=str1+str[j];
  if (str1<>'') and (StrToInt(str1)=b) then
  begin
    Writeln(i);
    Exit;
  end;
end;

Read(t2);
end.

var a,b:longint;
function dk(x,y:longint):boolean;
var r,hh:string;
int,i:longint;
begin
r:='';
dk:=false;
str(y,hh);
for i:=1 to length(hh) do if (hh[i]='4') or (hh[i]='7') then r:=r+hh[i];
val(r,int);
if int=x then dk:=true;
end;
//
begin

readln(a,b);
repeat
inc(a);
until dk(b,a);
writeln(a);
readln;
end.

var
 a,b,c,x,y,z:longint;
begin
readln(a,b);
if b>a then write(b) else
for c:=a+1 to 1000000 do
 begin
  x:=c;
  y:=1;
  z:=0;
  while x<>0 do
   begin
    if (x mod 10=4)or(x mod 10=7) then
     begin
      z:=(x mod 10)*y+z;
      y:=y*10;
     end;
    x:=x div 10;
   end;
  if z=b then
   begin
    write(c);
    halt;
   end;
 end;
end.

var n,k,e,i:longint;
    s:string;
begin
  readln(n,k);
  repeat
    n:=n+1;
    e:=0;
    str(n,s);
    for i:=1 to length(s) do
      begin
        if s[i]='4' then e:=e*10+4;
        if s[i]='7' then e:=e*10+7;
      end;
    if e=k then
      begin
        writeln(n);
        halt;
      end;
  until false;
end.

Uses SysUtils;
Var
   a,b,s,i:Integer;
   t,w:String;
Begin
   Read(a,b);
   s:=a+1;
   While True Do Begin
      t:=inttostr(s);
      w:='';
      For i:=1 To length(t) Do
         If (t[i]='4') or (t[i]='7') Then w:=w+t[i];
      If w=inttostr(b) Then Break;
      s:=s+1;
   End;
   Write(s);
End.

var
  i,j,l,a,b:longint;
  s1,s2:string;
begin
  readln(a,b);
  str(b,s1);
  i:=a+1;
  while true do begin
    l:=1;
    str(i,s2);
    for j:=1 to length(s2) do if (s2[j]='4') or (s2[j]='7') then begin
      if l=length(s1)+1 then begin inc(l); break; end;
      if s1[l]=s2[j] then inc(l) else break;
    end;
    if l=length(s1)+1 then break;
    inc(i);
  end;
  writeln(i);
end.

var bb,a,b,i:longint;

function mask(i:longint):longint;
var j,s:longint;
b:array [1..100] of byte;
begin
j:=1;
while i<>0 do begin
b[j]:=i mod 10;
i:=i div 10;
inc(j);
end;
dec(j);
s:=0;
for j:=j downto 1 do
if (b[j]=4) or (b[j]=7) then s:=(s+b[j])*10;
s:=s div 10;
mask:=s;
end;

begin
read(a,b);
i:=a+1;
while mask(i)<>b do
inc(i);
write(i);
end.

var a,b,c,i:longint;
function mask(a:longint):longint; var c,n,f:longint; p:byte;
begin n:=a; c:=0; f:=0;
repeat p:=n mod 10; if (p=4) or (p=7) then
begin if f=0 then f:=1 else f:=f*10; c:=c+f*p; end; n:=n div 10; until n=0;
mask:=c; end;
begin readln(a,b);
if b>a then begin write(b); exit; end;
i:=a; repeat inc(i); if mask(i)=b then begin writeln(i); exit; end;
until i>1000000;
end.

{$APPTYPE CONSOLE}
{R+,S+,Q+,I+,C+,M+,H+,O+}
{$R-,S-,Q-,I-,C+,M-,H+,O-}

uses
	SysUtils, Math;

var
	i, a, b : longint;

function mask(n : longint) : longint;

var
	i, cc : longint;
	a : array[0..20] of longint;

begin
	cc := 0;
	while n > 0 do begin
		if (n mod 10 = 4) or (n mod 10 = 7) then begin
			inc(cc);
			a[cc] := n mod 10;
		end;
		n := n div 10;
	end;
	result := 0;
	for i := cc downto 1 do
		result := result * 10 + a[i];
end;

begin
{$IFNDEF ONLINE_JUDGE}
	reset(input, 'input.txt');
	rewrite(output, 'output.txt');
{$ENDIF}
	read(a, b);
	i := a + 1;
	while true do begin
		if mask(i) = b then begin
			write(i);
			halt(0);
		end;
		inc(i);
	end;
end.

var
a,b:integer;

function pp(a1:integer):integer;
var m,mask,st:integer;
begin
mask:=0; st:=1;
while a1<>0 do
begin m:= a1 mod 10;
if (m=7) or (m=4) then begin mask:=mask+m*st; st:=st*10; end;
a1:=a1 div 10;
end;
pp:=mask;
end;
begin
readln(a,b);
repeat
inc(a);
until pp(a)=b;
writeln(a);
end.

var
s,ss,sss:string;
a,b,i,j:longint;
begin
readln(a,b);
str(b,sss);
for i:=a+1 to 1000000 do begin
    str(i,s);
    ss:='';
    for j:=1 to length(s) do begin
        if (s[j]='4')or(s[j]='7') then ss:=ss+s[j];
    end;
    if (ss=sss)and(i>a) then begin
        writeln(i);
        break;
    end;
end;
end.

var n,f,i,a,b,s:longint;
Begin
        read(a,b);
        f:=0;
        while f=0 do
        begin
        a:=a+1;
        n:=a;
        s:=0;
        i:=0;
        while n>0 do
        begin
        if n mod 10 in[4,7] then s:=s*10+n mod 10;
        n:=n div 10;
        end;
        while s>0 do
        begin
        i:=i*10+s mod 10;
        s:=s div 10;
        end;
        if i=b then f:=1;
        end;
        writeln(a);
End.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  a, b, a1, i : integer;
  s : string;

begin

  read(a, b);
  while true do begin
    inc(a);
    s := inttostr(a);
    i := 1;
    while i <= length(s) do begin
      if (s[i] <> '4') and (s[i] <> '7') then
        delete(s, i, 1)
      else
        inc(i);
    end;
    if (length(s) > 0) and (strtoint(s) = b) then begin
      writeln(a);
      readln;readln;
      halt;
    end;
  end;

  readln;readln;
end.

{$mode objfpc}
{$S-, Q-, R-, I-, O+}
{-$S+, Q+, R+, I+, O+}
uses sysutils;
var
  a, b, c : longint;

  function m(c : longint) : longint;
  var
    s, s2 : string;
    i : integer;
  begin
    s := inttostr(c);
    s2 := '0';
    result := 0;
    for i:=1 to length(S) do
      if s[i] in ['4', '7'] then
        s2 := s2 + s[i];
    result := strtoint(s2);
  end;

begin
  readln(a, b);
  c := a + 1;
  while m(c) <> b do
    c := c + 1;
  write(c);
end.

program ProjectA;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

const
  inf = 1000000000000000000;

var
  n, k, i, c, res, a, b, w: integer;
  d: int64;
  ok: boolean;

procedure panic(x: integer);
begin
  write(x);
  halt(0);
end;

procedure swap(var qx, qy: integer);
var
  qz: integer;
begin
  qz := qx;
  qx := qy;
  qy := qz;
end;

function f(w: integer): integer;
var
  dc: integer;
begin
  dc := 0;
  While w > 0 do
        begin
          if (w mod 10 = 4) or (w mod 10 = 7) then
            dc := 10 * dc + w mod 10;
          w := w div 10;
        end;
  Result := dc;
end;

begin
  {$IFNDEF ONLINE_JUDGE}
  Reset(input, 'input.txt');
  Rewrite(output, 'output.txt');
  {$ENDIF}

  read(a, b);
  w := 0;
  While b > 0 do
    begin
      w := 10 * w + b mod 10;
      b := b div 10;
    end;
  b := w;
  for i := 1 to 1000000000 do
    begin
      c := f(i);
      if (c = b) and (i > a) then
        panic(i);
    end;

end.

var
    a,b,i:longint;

function numoff(x:longint):longint;
var
    i,ans:longint;
    tmp:string;
begin
    str(x,tmp);
    i:=1;
    while i<=length(tmp) do
    begin
        if (tmp[i]<>'4')and(tmp[i]<>'7') then delete(tmp,i,1)
        else inc(i);
    end;
    val(tmp,ans);
    exit(ans);
end;

begin
    readln(a,b);
    for i:=a+1 to 1000000 do
    if numoff(i)=b then
    begin
        writeln(i);
        halt;
    end;
end.
//By THCDUSMAN

var n,a,b,i,f,k,x,p:longint;s1,s2,s:string;
begin
readln(a,b);
str(a,s1);
str(b,s2);
if (a<b)or((length(s1)=length(s2))and(a<b))
then begin
     writeln(b);
     exit;
     end;
while k=0 do
begin
delete(s,1,length(s));
a:=a+1;
x:=a;
while x>0 do
begin
p:=x mod 10;
if (p=4)
then s:='4'+s
else if p=7
     then s:='7'+s;
x:=x div 10 ;
end;
if s2=s
then begin
     k:=1;
     writeln(a);
     exit;
     end;
end;
end.

var
  a,b:int64;
  i:longint;
  key,s,ss:ansistring;
begin
  read(a,b);
  if a<b
    then a:=b
    else begin
           key:='';
           str(b,key);
           inc(a);
           while true do
             begin
               s:='';
               str(a,s);
               ss:='';
               for i:=1 to length(s) do
                 if (s[i]='4')or(s[i]='7')
                   then ss:=ss+s[i];
               if ss=key then begin
                                write(a);
                                halt;
                              end;
               inc(a);
             end;
         end;
  write(a);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var a,b,c:integer;
    i:integer;
    x:char;
    s1:string;
    found:boolean;
function getmask(a:integer):string;
var old,mask:string;
    j,k:integer;
begin
    mask:='';
    old:=inttostr(a);
    for k:=1 to length(old) do
        if (old[k]='7') or (old[k]='4') then begin
            inc(j);
            mask:=mask+old[k];
        end;
    getmask:=mask;
end;
begin
    readln(a,b);
    if a<b then begin
        writeln(b);
        halt;
    end;
    inc(a);
    found:=false;
    while not found do begin
        if getmask(a)=inttostr(b) then found:=true else inc(a);
    end;
    {writeln(getmask(a));}
    if (found) then writeln(a);
end.

const
    finp='';
    fout='';
var a,KQ:string;
    x,y,i,x1,b,t:longint;
    f,g:text;
begin
    assign(f,finp); reset(f);
    assign(g,fout); rewrite(g);
    read(f,x,y);
    x1:=x;
    repeat
        inc(x);
        str(x,a);
        for i:=length(a) downto 1 do
            if (a[i]<>'4') and (a[i]<>'7') then
                delete(a,i,1);
        val(a,b,t);
    until (b=y) and (x>x1);
    str(x,KQ);
    write(g,KQ);
    close(f); close(g);
end.

uses
  sysutils, strutils, math;
type
  ex=extended;
  int=longint;
  bool=boolean;
var
  a,b,i: int;
  s: string;

function check(c: int): bool;
var
  i: int;
  t,r: string;
begin
t:= inttostr(c);
r:= '';
for i:= 1 to length(t) do
  if (t[i]='4')or(t[i]='7')
    then
      r:= r+t[i];
check:= (r=s);
end;

begin
readln(a,b);
s:= inttostr(b);
for i:= a+1 to 1777770 do
  if check(i)
    then
      begin
      writeln(i);
      exit;
      end;
end.

var a,b:longint;
function mask(a:longint):longint;
var x,k,c:longint;
begin
    c:=a;
    x:=1;
    k:=0;
    while c>0 do begin
        if (c mod 10=4)or(c mod 10=7) then begin
            k:=k+(c mod 10)*x;
            x:=x*10;
        end;
        c:=c div 10;
    end;
    mask:=k;
end;
begin
    readln(a,b);
    inc(a);
    while mask(a)<>b do
        inc(a);
    writeln(a);
    readln;
end.

program b_prob;
var
    i,j,k,m,n:longint;
    a,b,masklength:longint;
    s,t,mask:string;
procedure init;
begin
    readln(a,b);
    str(b,mask);
end;
function check(x:longint):boolean;
var i:longint;
begin
    str(x,s);n:=length(s);t:='';m:=0;
    for i:=1 to n do
        if (s[i]='4')or(s[i]='7') then
        begin
            inc(m);t:=t+s[i];
        end;
    if m<>masklength
                then check:=false
                else if t<>mask
                        then check:=false
                        else check:=true;

end;
procedure main;
begin
        masklength:=length(mask);
    i:=a+1;
    while not check(i) do
          inc(i);
    writeln(i);
end;
begin

    init;
    main;

end.

var
  i,j,l,a,b:longint;
  s1,s2:string;
begin
  readln(a,b);
  str(b,s1);
  i:=a+1;
  while true do begin
    l:=1;
    str(i,s2);
    for j:=1 to length(s2) do if (s2[j]='4') or (s2[j]='7') then begin
      if l=length(s1)+1 then begin inc(l); break; end;
      if s1[l]=s2[j] then inc(l) else break;
    end;
    if l=length(s1)+1 then break;
    inc(i);
  end;
  writeln(i);
end.

var
a,b,c,p,l,n,i,j,cuantos,total:longint;
cual,cad:string;
begin
     readln(a,b);
     str(b,cual);
     n:=length(cual);
     if b>a then
     begin
        writeln(b);
        halt;
     end;
     i:=a+1;
     while 0=0 do
     begin
          str(i,cad);
          l:=0;
          p:=length(cad);
          cuantos:=0;
          total:=0;
          for j:=1 to p do
              if (cad[j]='7') or (cad[j]='4') then
              begin
                 inc(total);
                 inc(l);
                 if (l<=n) and (cual[l]=cad[j]) then
                    inc(cuantos);
              end;
          if (cuantos=n) and (total=n) then
          begin
             writeln(i);
             halt;
          end;
          inc(i);
     end;
end.

var s,s1:string;
    c,i,j,f,a,b:longint;
begin
 readln(a,b);
 if a<b then writeln(b)
  else
   begin
    inc(a);
    while true do
     begin
      str(a,s);
      s1:='';
      i:=1;
      while i<=length(s) do
       begin
        if (s[i]='4') or (s[i]='7') then s1:=s1+s[i];
        inc(i);
       end;
      val(s1,c,f);
      if c=b then begin
                   writeln(a);
                   exit;
                  end;
      inc(a);
     end;
    end;
end.

const
        fi='';
        fo='';
var
        b,s:string;
        i,a:longint;

procedure doc;
begin
        assign(input,fi);
        reset(input);
        read(a); read(b);
        while b[1]=' ' do delete(b,1,1);
        close(input);
end;

function kt(s:string):boolean;
var     dem:longint;
begin
        dem:=0;
        for i:=1 to length(s) do
                if (s[i]='7') or (s[i]='4') then
                        inc(dem);
        if dem>length(b) then exit(false);
        for i:=1 to length(b) do
                begin
                        if length(s)=0 then exit(false);
                        if pos(b[i],s)=0 then exit(false);
                        delete(s,1,pos(b[i],s));
                end;
        kt:=true;
end;

procedure xuly;
begin
        str(a+1,s); a:=a+1;
        while kt(s)=false do
                begin
                        inc(a);
                        str(a,s);
                end;
end;

procedure ghi;
begin
        assign(output,fo);
        rewrite(output);
        write(a);
        close(output);
end;

begin
        doc;
        xuly;
        ghi;
end.

var
   a,b,p,ans:longint;
   c:array[1..100]of longint;
   i,j,n,m,k,s,t:longint;
function ok(p:longint):boolean;
begin
   k:=0;
   while p>0 do
   begin
      inc(k);
      c[k]:=p mod 10;
      p:=p div 10;
   end;
   ans:=0;
   for i:=k downto 1 do
     if (c[i]=4)or(c[i]=7) then
     ans:=ans*10+c[i];
   if ans=b then exit(true)
   else exit(false);
end;
begin
   readln(a,b);
   inc(a);
   while not ok(a) do
     inc(a);
   writeln(a);
end.

{$APPTYPE CONSOLE}

var
a,b,i,d,x,k,cur : longint;

begin
 readln (a,b);
 if b>a then
 begin
  writeln (b);
  exit;
 end;

 i:=a;
 while true do
 begin
  inc (i);
  d:=i;
  x:=0;
  cur:=1;
  while d<>0 do
  begin
   k:=d mod 10;
   if (k=7) or (k=4) then begin x:=k*cur+x;  cur:=cur*10; end;
   d:=d div 10;
  end;
  if x=b then
  begin
   writeln (i);
   exit;
  end;
 end;
end.

var
	x, code, a, b, c, i: longint;
	s: ansistring;

begin
 //	reset(input, 'a.in');
//	rewrite(output, 'a.out');
	readln(a, b);
	for i := a + 1 to 10000000 do begin
		s := ''; c := i;
		while (c > 0) do begin
			if (c mod 10 = 4) or (c mod 10 = 7) then
                                s := chr(c mod 10 + 48) + s;
			c := c div 10;
		end;
		val(s, x, code);
        if x = b then begin
        	write(i);
        	halt;
       	end;
	end;
end.

var
 s:ansistring;
 n,m,i,z,x,c,ss,d,r:longint;
 l:integer;
begin
 read(n,m);
 for i:=n+1 to 2000000 do
 begin
  x:=i;
  s:='';
  while x<>0 do
  begin
   z:=x mod 10;
   if (z=4)or(z=7)then s:=chr(z+48)+s;
   x:=x div 10;
  end;
  val(s,d,l);
  if d=m then
  begin
   writeln(i);
   halt;
  end;
 end;
end.

{$mode objfpc}
var
   a, b, c, i, j, n : Integer;

function check(x : Integer ): Integer;
var
   p, q, cs : Integer;
begin
   if x = 147 then
      c := 1;
   result := 0;
   cs := 1;
   while x > 0 do
      begin
         if (x mod 10 = 4) or (x mod 10 = 7) then
            begin
               result := (x mod 10) * cs + result;
               cs := cs * 10;
            end;
         x := x div 10;
      end;

end;

begin
   read(a, b);
   repeat
      a := a + 1;
      if check(a) = b then
         begin
            writeln(a);
            halt;
         end;
   until false;
end.

Var s,t:string;
    j,i,a,b,f,l,p:longint;
  begin
   read(a,b);
   for i:=a+1 to 10000000 do
    begin
     f:=i;
     str(f,t);
     s:='';
     for j:=1 to length(t) do
      if (t[j]='4') or (t[j]='7') then s:=s+t[j];
     val(s,l,p);
    if l=b then begin write(f); exit; end;
   end;
  end.

var
 i,j,n,m,k,kol,res:longint;
 ss,ans,sa,sb,s:string;
 f1,f2:integer;
begin
{ assign(input,'input.txt');
 reset(input);
 assign(output,'output.txt');
 rewrite(output);}
 readln(n,m);
 str(m,sb);
 while true do
 begin
  inc(n);
  str(n,sa);
  for i:=1 to length(sa) do if (sa[i]='4')or(sa[i]='7') then ss:=ss+sa[i];
  if ss=sb then break;
  ss:='';
 end;
 writeln(n);
end.

uses sysutils;
var
  A,B,C:longint;
function getMask(a:longint):longint;
var
  s,s2:string;
  i:byte;
begin
  s:=IntToStr(a);
  s2:='';
  for i := 1 to length(s) do
    if s[i] in ['7','4']
      then
        s2:=s2+s[i];
  if s2 = ''
     then
       s2:='0';
  getMask:=StrToInt(s2);
end;
begin
  read(A,B);
  for C:=A+1 to 1000000 do
    if getMask(C)=B
      then
        break;

  writeln(C);
end.

var s,s1:string;
n,i,a,c:longint;
function func(x:longint):longint;
var s:string;
j,st,b:longint;
begin
 str(x,s);s1:='';
 for j:=1 to length(s) do
  if (s[j]='4') or (s[j]='7') then s1:=s1+s[j];
 st:=1;b:=ord(s1[length(s1)])-ord('0');
 for j:=length(s1)-1 downto 1 do
  begin
   st:=st*10;
   b:=b+st*(ord(s1[j])-ord('0'));
  end;
func:=b;
end;
begin
read(a,c);inc(a);
while a=a do
 begin
  if func(a)=c then break;
  inc(a);
 end;
writeln(a);
 end.

var bb,s,f:string;
    i,a,b:longint;
procedure mask(v:longint);
begin
  str(v,s);
  f:='';
  for i:=1 to length(s) do
  if (s[i]='7')or(s[i]='4') then f:=f+s[i];
  if f=bb then begin writeln(v);halt;end;
end;
begin
   readln(a,b);
   str(b,bb);
   while a<=10000000 do
   begin
    inc(a);
        mask(a);
   end;
end.

program ProjecB;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
a,b,i:integer;
s:string;

function find(y:integer):integer;
  var
    x:array[1..100000] of integer;
    t,k,rez,u,j:integer;
  begin
  rez:=0;
  k:=0;
   while y>0 do
    begin
    t:=y mod 10;
    y:=y div 10;
    if t in [4,7] then
      begin
        inc(k);
        x[k]:=t;
      end;
     end;
  u:=1;
  for j:=1 to k do
    begin
      rez:=rez+x[j]*u;
      u:=u*10;
    end;
  find:=rez;
  end;
begin
  { TODO -oUser -cConsole Main : Insert code here }
readln(a,b);
inc(a);
while find(a)<>b do
  inc(a);
writeln(a);
end.

var
 a:array[0..10000] of longint;
 n,m,i,j,k,l:longint;
 c:char;
 s,s1,s2:string;
begin
  readln(n,m);
  str(m,s);
  i:=n+1;
  while true do
   begin
     str(i,s1);
     s2:='';
     for l:=1 to length(s1) do
      if s1[l] in ['4','7'] then s2:=s2+s1[l];

     if s2=s then break;
     inc(I);

   end;
  write(i);
end.

Var a,b,c,i:longint;
Function ktra(i:longint) :boolean;
        Var j:longint;
            tmp:String;
            s  :String;
            s1:longint;
        Begin
                Str(i,tmp);
                s:='';
                For j:=1 to length(tmp) do
                        Begin
                                If ( tmp[j]='4') or ( tmp[j]='7') then
                                        Begin
                                                s:=s+tmp[j];
                                        End;
                        End;
                Val(s,s1);
                If s1=b then ktra:=true else ktra:=false;
        End;

Begin
        Read(a,b);
        i:=a+1;
        repeat
                If (ktra(i)) then Begin Write(i); Readln; exit; End
                else inc(i);
        until false;

        Readln;
END.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n, m: int64;
  i: integer;
  s, ss: string;

function f(k: string): boolean;
var
  i: integer;
  sss: string;
begin
  result := false;
  for i := 1 to length(k) do begin
    if (k[i] = '4') then
      sss := sss + '4';
    if (k[i] = '7') then
      sss := sss + '7';
  end;
  if (sss = ss) then
    result := true;
end;

begin
{  reset(input, 'input.txt');
  rewrite(output, 'output.txt');}
  readln(n, m);

  if (n < m) then begin
    writeln(m);
    halt(0);
  end;

  s := IntToStr(m);
  for i := 1 to length(s) do begin
    if (s[i] = '4') then
      ss := ss + '4';
    if (s[i] = '7') then
      ss := ss + '7';
  end;

  for i := n + 1 to 20000000 do begin
    if (f(IntToStr(i))) then begin
      writeln(i);
      halt(0);
    end;
  end;

end.

var n,k,e,i:longint;
    s:string;
begin
  readln(n,k);
  repeat
    n:=n+1;
    e:=0;
    str(n,s);
    for i:=1 to length(s) do
      begin
        if s[i]='4' then e:=e*10+4;
        if s[i]='7' then e:=e*10+7;
      end;
    if e=k then
      begin
        writeln(n);
        halt;
      end;
  until false;
end.

var
  x,a,b,c,bb,cc:longint;

begin
  read(a,b);
  if (b>a)then begin
    writeln(b);
    exit;
  end;
  for c:=a+1 to 1000000000 do begin
    bb:=b;
    cc:=c;
    while (cc>0)do begin
      x:=cc mod 10;
      cc:=cc div 10;
      if (x<>4)and(x<>7)then continue;
      if (x<>bb mod 10)then begin
        bb:=-1;
        break;
      end;
      bb:=bb div 10;
    end;
    if (bb=0)then begin
      writeln(c);
      exit;
    end;
  end;
end.

const
   tfi='';
   tfo='';
var
   p,q:string;
   a,b:longint;

function mask(r:string):string;
var
   i:longint;
   res:string;
begin
   res:='';
   for i:=1 to length(r) do
      if (r[i]='4') or (r[i]='7') then
         res:=res+r[i];
   exit(res);
end;

procedure main;
begin
   assign(input,tfi); reset(input);
   assign(output,tfo); rewrite(output);
   read(a,b);
   str(b,q);
   repeat
      inc(a);
      str(a,p);
   until mask(p)=q;
   writeln(a);
   close(input); close(output);
end;

BEGIN
   main;
END.

{$APPTYPE CONSOLE}{$o-}{$r+}

uses
  SysUtils;

var
  i, a, b : integer;
  s, ans : string;

begin
  read(a, b);
  while ans <> inttostr(b) do
  begin
    inc(a);
    ans := '';
    s := inttostr(a);
    for i := 1 to length(s) do
      if (s[i] = '4') or (s[i] = '7') then
        ans := ans + s[i];
  end;
  write(a);
end.

var
  a,b,c,i,qw: longint;
function func(a : longint) : longint;
var
  s,so : string;
  u,i,code: longint;
begin
  s := '';
  str(a,so);
  for i := 1 to length(so) do
    if (so[i] = '4') or (so[i] = '7') then
      s := s + so[i];
  val(s,u,code);
  func := u;
end;
begin
  {assign(input, 'input.txt');
  assign(output, 'output.txt');
  reset(input);
  rewrite(output);}
  readln(a,b);
  c := a;
  while qw <> b do
  begin
    inc(c);
    qw := func(c);
  end;
  writeln(c);
end.

var
    a,b,i:longint;

function numoff(x:longint):longint;
var
    i,ans:longint;
    tmp:string;
begin
    str(x,tmp);
    i:=1;
    while i<=length(tmp) do
    begin
        if (tmp[i]<>'4')and(tmp[i]<>'7') then delete(tmp,i,1)
        else inc(i);
    end;
    val(tmp,ans);
    exit(ans);
end;

begin
    readln(a,b);
    for i:=a+1 to 1000000 do
    if numoff(i)=b then
    begin
        writeln(i);
        halt;
    end;
end.
//By THCDUSMAN

Var     x, s4, so4, s7, so7, a, b, i : longint;

Function mask(i:longint):longint;
 Var    s : string;
        b : longint;
 Begin
        s := '';
        str(i,s);
        for i:=length(s) downto 1 do
                if (s[i] <> '4') and (s[i] <> '7') then delete(s,i,1);
        val(s,b,i);
        mask := b;
 End;

Begin
        readln(a,b);
        for i:=a+1 to 1000000 do begin
                x := mask(i);
                if x = b then begin
                        writeln(i);
                        exit;
                end;
        end;
End.

var n,i,a,b,x,k:longint;
    p:integer;
    s:string;
begin
  read(a,b);
  x:=a;
  k:=x;
  repeat
    inc(x);
    str(x,s);
    for i:=length(s) downto 1 do if (s[i]<>'4') and (s[i]<>'7') then delete(s,i,1);
    val(s,k,p);
  until k=b;
  writeln(x);
end.

var s,mm,ss:ansistring;
n,m,i,lik,a,b:longint;
s1:string;
begin
readln(n,m);
str(m,mm);
for i:=length(mm) downto 1 do
ss:=ss+mm[i];
for i:=n+1 to 999999999 do
begin
 a:=i;
 s:='';
 while a<>0 do
   begin
   b:=a mod 10;
   str(b,s1);
   if (s1='4')or(s1='7') then  s:=s+s1;
   a:=a div 10;

   end;
    if s=ss then begin writelN(i);halt;end;

end;

end.

program CF_104_2_B;

{$APPTYPE CONSOLE}
{$R-,Q-}

uses
  SysUtils;

var
	a, k, c, b, i: integer;
	a_s, b_s, n_s : string;
begin
	readln(a, b);
	c:=0;
  a:=a+1;
  N_s:='';
	b_s := IntToStr(b);
 	while c=0 do begin
		a_s := IntToStr(a);
    for i:=1 to length (a_s) do
      begin
        if (a_s[i]=('4')) or (a_s[i]=('7')) then n_s:=n_s+a_s[i];
      end;
    if n_s=b_s then
			begin
        inc(c);
        write(a_s);
			end
		else begin inc(a); n_s:=(''); end
	end;
	readln;
end.

var a,b:longint;
function mask(a:longint):longint;
var x,k,c:longint;
begin
    c:=a;
    x:=1;
    k:=0;
    while c>0 do begin
        if (c mod 10=4)or(c mod 10=7) then begin
            k:=k+(c mod 10)*x;
            x:=x*10;
        end;
        c:=c div 10;
    end;
    mask:=k;
end;
begin
    readln(a,b);
    inc(a);
    while mask(a)<>b do
        inc(a);
    writeln(a);
    readln;
end.

var a,b,c,i:longint;
function mask(a:longint):longint; var c,n,f:longint; p:byte;
begin n:=a; c:=0; f:=0;
repeat p:=n mod 10; if (p=4) or (p=7) then
begin if f=0 then f:=1 else f:=f*10; c:=c+f*p; end; n:=n div 10; until n=0;
mask:=c; end;
begin readln(a,b);
if b>a then begin write(b); exit; end;
i:=a; repeat inc(i); if mask(i)=b then begin writeln(i); exit; end;
until i>1000000;
end.

var a,b,i,j:longint;
    a1,b1:string;
begin
 readln(a,b);
 if a<b then begin writeln(b);exit;end;
 str(b,b1);
 for i:=a+1 to 97999 do begin
   str(i,a1);
    j:=1;
    while j<=length(a1) do
      if (a1[j]<>'4') and (a1[j]<>'7') then delete(a1,j,1) else j:=j+1;
    if pos(b1,a1)<>0 then break;end;
 writeln(i);
end.

var n,a,b,i,f,k,x,p:longint;s1,s2,s:string;
begin
readln(a,b);
str(a,s1);
str(b,s2);
if (a<b)or((length(s1)=length(s2))and(a<>b))
then begin
     writeln(b);
     exit;
     end;
while k=0 do
begin
delete(s,1,length(s));
a:=a+1;
x:=a;
while x>0 do
begin
p:=x mod 10;
if (p=4)
then s:='4'+s
else if p=7
     then s:='7'+s;
x:=x div 10 ;
end;
if s2=s
then begin
     k:=1;
     writeln(a);
     exit;
     end;
end;
end.

var s,s1:string;
    n,i,k,k1,k2,k4,k7,min:longint;
begin
 readln(s,s1);
 n:=length(s);
 for i:=1 to n do
  begin
   if (s[i]='7')and(s1[i]='4') then k7:=k7+1;
   if (s[i]='4')and(s1[i]='7') then k4:=k4+1;
  end;
 if k7<=k4 then min:=k7
  else min:=k4;
 k:=min;
 k1:=k7-k;
 k2:=k4-k;
 k:=k+k1+k2;
 writeln(k+1);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n, m: int64;
  hh, ss, i: integer;
  s: string;

function f(k: string): boolean;
var
  he, se, i: integer;
begin
  result := false;
  he := 0;
  se := 0;
  for i := 1 to length(k) do begin
    if (k[i] = '4') then
      inc(he);
    if (k[i] = '7') then
      inc(se);
  end;
  if (he >= hh) and (se >= ss) then
    result := true;
end;

begin
  {reset(input, 'input.txt');
  rewrite(output, 'output.txt');}
  readln(n, m);

  if (n < m) then begin
    writeln(m);
    halt(0);
  end;

  ss := 0;
  hh := 0;
  s := IntToStr(m);
  for i := 1 to length(s) do begin
    if (s[i] = '4') then
      inc(hh);
    if (s[i] = '7') then
      inc(ss);
  end;

  for i := n + 1 to 20000000 do begin
    if (f(IntToStr(i))) then begin
      writeln(i);
      halt(0);
    end;
  end;

end.

var
a,b,c,d,k:longint;
begin
read(a,b);
if a=b then
begin
write(a);
halt;
end;
c:=a; if c<>b then
while d<>b do
begin
a:=a+1;
c:=a;
d:=0;
k:=1;
while c>0 do
begin
if (c MOD 10 = 4) or (C MOD 10 = 7)
then begin
d:=(c Mod 10)*k +d;
k:=k*10;
end;
c:=c DIV 10
end;
end;
write(a);
end.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q+,R+,S-,T-,U-,V+,W-,X+,Y+,Z1}
uses sysutils;
var a,b,c,x,i,t:LongInt;
function MySort(a:LongInt;var b:longint):boolean;
var c:Char;
    i:Integer;
    s:string;
begin
  s:=IntToStr(a);
  result:=False;
  for i:=1 to Length(s)-1 do
  begin
    if (s[i]='0')and(s[i+1]<>'0')
    then begin
        c:=s[i];
        s[i]:=s[i+1];
        s[i+1]:=c;
        result:=True;
        b:=StrToInt(s);
        exit;
    end;
  end;
  b:=StrToInt(s);
end;
begin
   //reset(input,'input.txt');
   //rewrite(output,'output.txt');
   Readln(a,b);
   c:=b;
   x:=1;
   for i:=1 to Length(inttostr(b)) do
   x:=x*10;
   if b>a
   then begin
     writeln(b);
     halt(0);
   end;
   while a>=c+x do
   begin
     t:=c+x;
     while (MySort(t,t))and(a>=t) do ;
     if a>=t
     then x:=x*10
     else begin
        writeln(c+x);
        Halt(0);
     end;
   end;
   writeln(c+x);
end.

program luckymask;

{$APPTYPE CONSOLE}
var i,a,b:longint; sa,sb:string;
function cmask(n:longint):boolean;
var j:integer; z,m:string;
begin
  str(n,z);
  m:='';
  result:=false;
  for j:=1 to length(z) do
    if (z[j]='4') or (z[j]='7') then m:=m+z[j];
  result:=m=sb;
end;
begin
  readln(a,b);
  str(a,sa);
  str(b,sb);
  (*if length(sb)>=length(sa) then
  begin
    writeln(sb);
    exit;
  end;*)
  for i:=a to 10000000 do
  begin
    if cmask(i) then
    begin
      writeln(i);
      //readln;
      exit;
    end;
  end;
end.

var
 a,b:longint;
begin
readln(a,b);
if b>a then write(b) else write('1',b);
end.

const
    finp='';
    fout='';
var a,b,KQ:string;
    x,y:longint;
    f,g:text;
function sosanh(s1,s2:string):boolean;
var i:longint;
begin
    if length(s1)>length(s2) then exit(true);
    if length(s1)<length(s2) then exit(false);
    for i:=1 to length(s1) do
        begin
            if ord(s1[i])>ord(s2[i]) then exit(true);
            if ord(s1[i])<ord(s2[i]) then exit(false);
        end;
    exit(false);
end;
{---------------------}
begin
    assign(f,finp); reset(f);
    assign(g,fout); rewrite(g);
    read(f,x,y);
    str(x,a); str(y,b);
    KQ:=b;
    while sosanh(KQ,a)=false do insert('1',KQ,1);
    write(g,KQ);
    close(f); close(g);
end.

var
a,b,i,j:longint;
s,ss:string;
begin
readln(a,b);
str(a,s);
str(b,ss);
if length(s)<=length(ss) then writeln(ss)
else begin
i:=1;
for j:=1 to length(s) do begin
    if s[j]>=ss[i] then begin
        s[j]:=ss[i];
        inc(i);
    end;
end;
for j:=1 to length(s)-length(ss) do write(s[j]);
if i<=length(ss) then
for j:=i to length(ss) do write(ss[j]);
end;
end.

var
 i,j,o,n,m,a,b,x,t,y,x1,y1:longint;
 s:string;

 function f (x:longint):boolean;
 var s1:string;
 begin
  s1:='';
  while x>0 do
  begin
   if x mod 10 = 4 then s1:=s1+'0' else
    if x mod 10 =7 then s1:=s1+'1';
   x:=x div 10;
  end;
  if s1=s then
  begin
   writeln(a);
   halt;
  end;
 end;
begin
 readln(a,b);
 if a<=b then
 begin
  writeln(b);
  halt;
 end;
 while b>0 do
 begin
  if b mod 10 = 4 then s:=s+'0' else s:=s+'1';
  b:=b div 10;
 end;

 while true do
 begin
  inc(a);
  f(a);
 end;
end.

var
a,b,c:longint;
begin
read(a,b);
if b>a then write(b) else write(1,b); end.

program ProjectA;

{$APPTYPE CONSOLE}
{$A+,B-,D-,E+,F+,G-,I-,L-,N+,R-,Q-,S-,V+,X+}

uses
  SysUtils,
  Math;

const
  inf = 1000000000000000000;

var
  n, k, i, c, res, a, b, w: integer;
  d: int64;
  ok: boolean;

procedure panic(x: integer);
begin
  write(x);
  halt(0);
end;

procedure swap(var qx, qy: integer);
var
  qz: integer;
begin
  qz := qx;
  qx := qy;
  qy := qz;
end;

begin
  {$IFNDEF ONLINE_JUDGE}
  Reset(input, 'input.txt');
  Rewrite(output, 'output.txt');
  {$ENDIF}

  read(a, b);
  n := 0;
  c := b;
  While c > 0 do
    begin
      n := n + 1;
      c := c div 10;
    end;
  k := -1;
  While True do
    begin
      inc(k);
      w := k;
      ok := true;
      While w > 0 do
        begin
          if (w mod 10 = 4) or (w mod 10 = 7) then
            ok := false;
          w := w div 10;
        end;
      if not ok then continue;
      d := trunc(power(10, n)) * k + b;
      if trunc(power(10, n)) * k + b > a then
        begin
          write(d);
          exit;
        end;
    end;

end.

var a,b,x:longint;
    s,t:string;
begin
 readln(a,b);
 str(b,s);
 if a<=b then begin writeln(b);halt(0)end;
 while true do
 begin
  t:='';
  x:=a;
  while a<>0 do
  begin
   if a mod 10=4 then t:='4'+t;
   if a mod 10=7 then t:='7'+t;
   a:=a div 10;
  end;
  a:=x;
  if t=s then begin writeln(a);halt(0);end;
  inc(a);
 end;
end.

var
 n,m,i:longint;
function mask(i:longint):longint;
 var
  s1,s2:string;
  j,t:longint;
 begin
  s1:='';s2:='';
  str(i,s1);
  for j:=1 to length(s1) do
   if (s1[j]='4') or (s1[j]='7')
    then s2:=s2+s1[j];
  val(s2,t);mask:=t;
 end;
begin
 readln(n,m);
 i:=n-1;
 repeat
  inc(i);
 until mask(i)=m;
 writeln(i);
end.

var
a,b:integer;

function pp(a1:integer):integer;
var m,mask,st:integer;
begin
mask:=0; st:=1;
while a1<>0 do
begin m:= a1 mod 10;
if (m=7) or (m=4) then begin mask:=mask+m*st; st:=st*10; end;
a1:=a1 div 10;
end;
pp:=mask;
end;
begin
read(a,b);
writeln;
while pp(a)<>b do inc(a);
writeln(a);
end.

var
a,b,i,j:longint;
s,ss:string;
begin
readln(a,b);
str(a,s);
str(b,ss);
if length(s)<=length(ss) then writeln(ss)
else begin
i:=1;
for j:=1 to length(s) do begin
    if s[j]>=ss[i] then begin
        s[j]:=ss[i];
        inc(i);
    end;
end;
for j:=1 to length(s)-length(ss) do write(s[j]);
for j:=i to length(ss)+1 do write(ss[j]);
end;
end.

var
  n,m,i,j,x,code	:	longint;
  s,t			:	ansistring;
begin
//   reset(input,'a.in');   rewrite(output,'a.out');
    read(n,m);
    for i:=n to 800000 do begin
    	str(i,s);
    	t:='';
    	for j:=1 to length(s) do
    		if s[j] in ['4','7'] then t:=t + s[j];
    	val(t,x,code);
    	if x = m then begin
    		write(i);
    		halt;
    	end;
    end;
end.

var a,b,n:longint;
    st1,st2,y,stroka:string;
    i,x,x1,x2,q,kluch,k,min:longint;
    code:integer;
begin
  readln(a,b);
  str(a,st1);
  str(b,st2);
  min:=1000000;
  if (length(st1)>length(st2)) or (a>=b)
  then
  begin
    if (a>=b) and (length(st1)=length(st2))
    then
    begin
      n:=length(st1);
      st1:='1';
      for i:=1 to n do
        st1:=st1+'0';
      val(st1,a,code);
    end;
    while kluch=0 do
    begin
      for i:=length(st1)-length(st2)+1 downto 1 do
      begin
        str(a,st1);
        k:=0;
        while k=0 do
        begin
          val(st1[i],x1,code);
          val(st2[1],x2,code);
          if x2>=x1
          then
          begin
            q:=0;
            while (x2=x1) and (i+q+1<=length(st1)) do
            begin
              inc(q);
              val(st1[i+q],x1,code);
              val(st2[1+q],x2,code);
            end;
            if x2>=x1
            then
            begin
              q:=0;
              while i+q<=length(st1) do
              begin
                if q<=length(st2)-1
                then st1[i+q]:=st2[1+q]
                else st1[i+q]:='0';
                inc(q);
              end;
              str(a,stroka);
              if stroka<>st1
              then
              begin
                val(st1,x,code);
                if x<min
                then min:=x
                else
                begin
                  kluch:=1;
                  break;
                end;
              end;
            end
          end;
          if kluch=0
          then
          begin
            val(st1[i-1],x,code);
            if (x=9) or (i=1)
            then
            begin
              k:=1;
              break;
            end
            else
            begin
              inc(x);
              str(x,y);
              val(st2[1],x1,code);
              insert(y,st1,i-1);
              delete(st1,i,1);
              for q:=i to length(st1) do
                st1[q]:='0';

            end;
          end;
        end;
      end;
      if x=9
      then break;
      if kluch=1
      then break;
      if kluch=1
      then break;
      if kluch=0
      then
      begin
        n:=length(st1);
        st1:='1';
        for q:=1 to n do
          st1:=st1+'0';
        val(st1,a,code);
      end;
    end;
    writeln(min);
  end
  else writeln(b);
end.

var n,i,a,b,x,k:longint;
    p:integer;
    s:string;
begin
  read(a,b);
  x:=a;
  k:=x;
  while k<>b do
  begin
    inc(x);
    str(x,s);
    for i:=length(s) downto 1 do if (s[i]<>'4') and (s[i]<>'7') then delete(s,i,1);
    val(s,k,p);
  end;
  writeln(x);
end.

var aa,bb,s,t:string;
a,b,c,d,e,f,g,i,j:longint;
z:array[0..9] of longint;
zz:array[0..9] of longint;
begin
    readln(a,b);
    str(b,bb);
    for i:=1 to length(bb) do
        begin
            inc(zz[ord(bb[i])-48]);
        end;
    for i:=a to 777777 do
        begin
             str(i,aa);
             if i>a then
                begin
                    for j:=1 to length(aa) do
                        begin
                            inc(z[ord(aa[j])-48]);
                        end;
                    if (z[4]>=zz[4]) and (z[7]>=zz[7]) then
                        begin
                        writeln(i);
                        halt;
                        end;
                    fillchar(z,sizeof(z),0);
                end;
        end;
end.

var a,b,n:longint;
    st1,st2:string;
    i,x,x1,x2,q:longint;
    code:integer;
begin
  readln(a,b);
  str(a,st1);
  str(b,st2);
  if (length(st1)>length(st2)) or (a>=b)
  then
  begin
    if (a>=b) and (length(st1)=length(st2))
    then
    begin
      n:=length(st1);
      st1:='1';
      for i:=1 to n do
        st1:=st1+'0';
    end;
    for i:=length(st1)-length(st2)+1 downto 1 do
    begin
      val(st1[i],x1,code);
      val(st2[1],x2,code);
      if x2>=x1
      then
      begin
        q:=0;
        while (x2=x1) and (i+q+1<=length(st1)) do
        begin
          inc(q);
          val(st1[i+q],x1,code);
          val(st2[1+q],x2,code);
        end;
        if x2>x1
        then
        begin
          q:=0;
          while i+q<=length(st1) do
          begin
            st1[i+q]:=st2[1+q];
            inc(q);
          end;
          writeln(st1);
          break;
        end;
      end;
    end;
  end
  else writeln(b);
end.

var
 c:integer;
 s,ss:string;
 x:int64;
 a,b,n,i,j,k:longint;
begin
 readln(a,b);
 for i:=a+1 to 10000 do
 begin
  s:='';
  ss:='';
  c:=0;
  x:=0;
  str(i,s);
  for j:=1 to length(s) do if (s[j]='4') or (s[j]='7') then insert(s[j],ss,300);
  val(ss,x,c);
  if x=b then
  begin
   writeln(s);
   halt;
  end;
 end;
end.

var a,b:longint;

function f(a:longint):longint;
var k,aa,s:longint;
begin
k:=0;
aa:=a;
while aa<>0 do begin
aa:=aa div 10;
inc(k);
end;
s:=round(exp(ln(10)*k));
f:=a+s;
end;

begin
read(a,b);

while b<=a do
b:=f(b);
write(b);
end.

var a,b,x,c,p:int64;
    i,m:longint;
begin
  readln(a,b);
  for i:=a+1 to 1000010 do
   begin
     x:=i;
     p:=1;
     c:=0;
     while x<>0 do
      begin
        m:=x mod 10;
        if (m=7) or (m=4) then c:=c+p*m;
        x:=x div 10;
        p:=p*10;
      end;
     if c=b then break;
   end;
  writeln(i);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var i,a,b:integer;

function mask(S:string):string;
var x:string;
    i:integer;
begin
x:='';
for i:=1 to length(s) do
 if (s[i]='4') or (s[i]='7') then x:=x+s[i];
mask:=x;
end;

begin
readln(a,b);
for i:=a to 1000000 do
 if mask(inttostr(i))=inttostr(b) then begin write(i); readln; halt; end;
end.

var aa,bb,s,t:string;
a,b,c,d,e,f,g,i,j:longint;
z:array[0..9] of longint;
zz:array[0..9] of longint;
begin
    readln(a,b);
    str(b,bb);
    for i:=1 to length(bb) do
        begin
            inc(zz[ord(bb[i])-48]);
        end;
        i:=a;
    while false do
        begin
             inc(i);
             str(i,aa);
             if i>a then
                begin
                    for j:=1 to length(aa) do
                        begin
                            inc(z[ord(aa[j])-48]);
                        end;
                    if (z[4]>=zz[4]) and (z[7]>=zz[7]) then
                        begin
                        writeln(i);
                        halt;
                        end;
                    fillchar(z,sizeof(z),0);
                end;
        end;
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var a,b,c:integer;
    i:integer;
    x:char;
    s1:string;
    found:boolean;
function getmask(a:integer):string;
var old,mask:string;
    j,k:integer;
begin
    old:=inttostr(a);
    for k:=1 to length(old) do
        if (old[k]='7') or (old[k]='4') then begin
            inc(j);
            mask:=mask+old[k];
        end;
    getmask:=mask;
end;
begin
    readln(a,b);
    if a<b then begin
        writeln(b);
        halt;
    end;
    found:=false;
    while not found do begin
        if getmask(a)=inttostr(b) then found:=true else inc(a);
    end;
    {writeln(getmask(a));}
    if (found) then writeln(a);
end.

Var a,b,c,i:longint; s,ss:string;

Procedure com;
Var i:longint;
Begin

if length(s)>length(ss) then begin Writeln(s); halt; end;
if length(s)<length(ss) then exit;

for i:=1 to length(s) do if ss[i]>s[i] then exit
                                       else
                         if ss[i]<s[i] then begin Writeln(s); halt; end;

end;

Begin

Readln(a,b); if a<b then Writeln(b) else Begin

ss:=''; While a>0 do begin ss:=char(a mod 10+48)+ss; a:=a div 10; end;

s:=''; While b>0 do begin s:=char(b mod 10+48)+s; b:=b div 10; end;

While length(ss)-length(s)>1 do s:='0'+s;

s:='0'+s; for i:=1 to 9 do if (i<>4)and(i<>7) then begin delete(s,1,1);s:=char(i+48)+s; com; end;

delete(s,1,1); Writeln('10',s);

end;

End.

var a,b,i,j:longint;
    a1,b1:string;
begin
 readln(a,b);
 if a<b then begin writeln(b);exit;end;
 str(b,b1);
 for i:=a+1 to 97999 do begin
   str(i,a1);
    j:=1;
    while j<=length(a1) do
      if (a1[j]<>'4') and (a1[j]<>'7') then delete(a1,j,1) else j:=j+1;
    if b1=a1 then break;end;
 writeln(i);
end.

var
a,b,c,i,k:longint;
s,st:string;
procedure check;
var stt:string;
begin
stt:='';
str(a,s);
for i:=1 to length(s) do
if (s[i]='4')or(s[i]='7') then stt:=stt+s[i];
if stt=st then begin
if k=a then exit;
writeln(a);
halt
end;
end;

begin
readln(a,b);k:=a;
if a<b then
  begin
  writeln(b);
  exit;
  end;
str(b,st);

while (a mod 10<>4)and(a mod 10<>7) do inc(a);
while true do
   begin
    check;
	inc(a);
	end;
end.

var
 c:integer;
 s,ss:string;
 x,a,b,n,i,j,k:longint;
begin
 readln(a,b);
 for i:=a+1 to 10000 do
 begin
  s:='';
  ss:='';
  c:=0;
  x:=0;
  str(i,s);
  for j:=1 to length(s) do if (s[j]='4') or (s[j]='7') then insert(s[j],ss,300);
  val(ss,x,c);
  if x=b then
  begin
   writeln(s);
   halt;
  end;
 end;
end.

var
a,b,c,i:longint;
s,st:string;
procedure check;
var stt:string;
begin
stt:='';
str(a,s);
for i:=1 to length(s) do
if (s[i]='4')or(s[i]='7') then stt:=stt+s[i];
if stt=st then begin
writeln(a);
halt
end;
end;

begin
readln(a,b);
if a<b then
  begin
  writeln(b);
  exit;
  end;
str(b,st);
while (a mod 10<>4)and(a mod 10<>7) do inc(a);
while true do
   begin
    check;
	if a mod 10=4 then inc(a,3)
	else inc(a,7);
	end;
end.

const fin='';
var f:text;
     a,b:longint;
function kt(a:longint):boolean;
var i,k,d,j:integer;
     s1:string;
begin
     str(a,s1); k:=1; d:=0;
     for i:=1 to length(s1) do
          if (s1[i]<>'4') and (s1[i]<>'7') then delete(s1,i,1);
     val(s1,k,j);
     kt:=k=b;
end;
begin
     assign(f,fin); reset(f);
     read(f,a,b);
     repeat
          inc(a);
     until kt(a);
     write(a);
end.

const
        fi='';
        fo='';
var
        b,s:string;
        i,a:longint;

procedure doc;
begin
        assign(input,fi);
        reset(input);
        readln(a);
        readln(b);
        close(input);
end;

function kt(s:string):boolean;
begin
        for i:=1 to length(b) do
                begin
                        if length(s)=0 then exit(false);
                        if pos(b[i],s)=0 then exit(false);
                        delete(s,1,pos(b[i],s));
                end;
        kt:=true;
end;

procedure xuly;
begin
        str(a,s);
        while kt(s)=false do
                begin
                        inc(a);
                        str(a,s);
                end;
end;

procedure ghi;
begin
        assign(output,fo);
        rewrite(output);
        write(a);
        close(output);
end;

begin
        doc;
        xuly;
        ghi;
end.

var a,b,n:longint;
    st1,st2,y,stroka:string;
    i,x,x1,x2,q,kluch,k:longint;
    code:integer;
begin
  readln(a,b);
  str(a,st1);
  str(b,st2);
  if (length(st1)>length(st2)) or (a>=b)
  then
  begin
    if (a>=b) and (length(st1)=length(st2))
    then
    begin
      n:=length(st1);
      st1:='1';
      for i:=1 to n do
        st1:=st1+'0';
    end;
    while kluch=0 do
    begin
      for i:=length(st1)-length(st2)+1 downto 1 do
      begin
        k:=0;
        while k=0 do
        begin
          val(st1[i],x1,code);
          val(st2[1],x2,code);
          if x2>=x1
          then
          begin
            q:=0;
            while (x2=x1) and (i+q+1<=length(st1)) do
            begin
              inc(q);
              val(st1[i+q],x1,code);
              val(st2[1+q],x2,code);
            end;
            if x2>=x1
            then
            begin
              q:=0;
              while i+q<=length(st1) do
              begin
                if q<=length(st2)-1
                then st1[i+q]:=st2[1+q]
                else st1[i+q]:='0';
                inc(q);
              end;
              str(a,stroka);
              if stroka<>st1
              then
              begin
                writeln(st1);
                kluch:=1;
                break;
              end;
            end
          end;
          if kluch=0
          then
          begin
            val(st1[i-1],x,code);
            if (x=9)
            then
            begin
              k:=1;
              break;
            end
            else
            begin
              inc(x);
              str(x,y);
              val(st2[1],x1,code);
              insert(y,st1,i-1);
              delete(st1,i,1);
              for q:=i to length(st1) do
                st1[q]:='0';
            end;
          end;
        end;
        if x=9
        then break;
        if kluch=1
        then break;
      end;
      if kluch=1
      then break;
      if kluch=0
      then
      begin
        n:=length(st1);
        st1:='1';
        for q:=1 to n do
          st1:=st1+'0';
      end;
    end;
  end
  else writeln(b);
end.

var
 i,j,n,m,k,kol,res:longint;
 ans,sa,sb,s:string;
 f1,f2:integer;
begin
{ assign(input,'input.txt');
 reset(input);
 assign(output,'output.txt');
 rewrite(output);  }
 readln(n,m);
 str(m,sb);
 while true do
 begin
  inc(n);
  str(n,sa);
  for i:=1 to length(sa) do if (sa[i]<>'4')and(sa[i]<>'7') then delete(sa,i,1);
  if sa=sb then break;
 end;
 writeln(n);
end.

{$APPTYPE CONSOLE}

uses
  SysUtils;
var str:string;
 n,i,sum:integer;
 bool:boolean;
 a,b,c:integer;
 function mask(a:integer):string;
 var s:string;
 begin
  s:='';
  while a>0 do begin
   if a mod 10 in [4,7] then s:=chr(a mod 10 + 48)+s;
   a:=a div 10;
  end;
  mask:=s;
  end;
  var st:string;
begin
read(a);
readln(b);
st:=inttostr(b);
str:=inttostr(a);
if length(str)<length(st) then writeln(b) else
if length(str)=length(st) then if b>a then writeln(b) else writeln(1,b)
else begin
 for i:=1 to length(str)-length(st)-1 do st:='0'+st;
 st:='1'+st;
 writeln(st);
 halt;
end;

end.

var
 a,b:longint;
begin
readln(a,b);
if b>a then write(b) else write('1',b);
end.

var a,b,c,t,x: longint;
begin
    read(a,b);
    if a<b then begin writeln(b); halt end;
    x:=b; t:=1;
    repeat
      x:=x div 10; t:=t*10;
    until x=0;

    c:=b;
    repeat
      c:=c+t;
    until (c>a);
    writeln(c)

end.

var a,b,i,j:longint;
    a1,b1:string;
begin
 readln(a,b);
 if a<b then begin writeln(b);exit;end;
 str(b,b1);
 for i:=a+1 to 1000000 do begin
   str(i,a1);
    j:=1;
    while j<=length(a1) do
      if (a1[j]<>'4') and (a1[j]<>'7') then delete(a1,j,1) else j:=j+1;
    if pos(b1,a1)<>0 then break;end;
 writeln(i);
end.

var a,b,c,i,k,aa:longint;
    x:array[1..10]of integer;

begin
 read(a,b);
 if a<=b then write(b) else begin
 while true do
  begin
   k:=0;
   c:=0;
   aa:=a;
   while a>0 do
    begin
     if a mod 10= 4 then begin inc(k);x[k]:=4; end;
     if a mod 10= 7 then begin inc(k);x[k]:=7; end;
     a:=a div 10;
    end;
   for i:=k downto 1 do
    c:=c*10+x[i];
   if c=b then begin writeln(aa);break; end;
   a:=aa;
   inc(a);

  end;
 end;
end.

program luckymask;

{$APPTYPE CONSOLE}
var i,a,b:longint; sa,sb:string;
function cmask(n:longint):boolean;
var j:integer; z,m:string;
begin
  str(n,z);
  m:='';
  result:=false;
  for j:=1 to length(z) do
    if (z[j]='4') or (z[j]='7') then m:=m+z[j];
  result:=m=sb;
end;
begin
  readln(a,b);
  str(a,sa);
  str(b,sb);
  (*if length(sb)>=length(sa) then
  begin
    writeln(sb);
    exit;
  end;*)
  for i:=a to 1000000 do
  begin
    if cmask(i) then
    begin
      writeln(i);
      //readln;
      exit;
    end;
  end;
end.

uses sysutils;
var
  A,B,C:longint;
function getMask(a:longint):longint;
var
  s:string;
  i:byte;
begin
  s:=IntToStr(a);
  for i := 1 to length(s) do
    if not (s[i] in ['7','4'])
      then
        delete(s,i,1);
  if s = ''
     then
       s:='0';
  getMask:=StrToInt(s);
end;
begin

  read(A,B);
  for C:=A+1 to 1000000 do
    if getMask(C)=B
      then
        break;

  writeln(C);
end.

var
i,a,b:longint;
aa,bb,w:string;
 begin
  readln(a,b);
  a:=a+1;
  str(b,bb);
  while true do
    begin
     str(a,aa);
     w:='';
     for i:=1 to length(aa) do
       if aa[i] in ['4'..'7'] then w:=w+aa[i];

     if w=bb then break;
     a:=a+1;
    end;
  writeln(a);
 end.

Program zad2;

Var
 q1, q2: longint;

Function mas (x: longint): longint;
 var
  sum, q, w: longint;
 begin
  sum:=0;
  q:=1000000;
  while x div q=0 do
   q:=q div 10;
  while q>0 do
   begin
    w:=x div q-(x div (q*10))*10;
    if (w=4) or (w=7)
     then sum:=sum*10+w;
    q:=q div 10;
   end;
  mas:=sum;
 end;

Begin
 {assign, (input, 'input.txt');
 assign (output, 'output.txt');
 reset (input);
 rewrite (output);}
 readln (q1, q2);
 if q1<q2
  then
   begin
    writeln (q2);
    halt (0);
   end;
 while mas(q1)<>q2 do
  inc (q1);
 writeln (q1);
End.

var a,b,c,i,j,q,k,e:longint;
begin
read(a,b);
if a < b then begin write(b); exit; end;
c:=a;

if a > b then
while i<>1 do begin

  inc(C);
  j:=c;
  k:=0;
  e:=1;
    while j<> 0 do
    begin
     q:=j mod 10;
     j:=j div 10;
     if (q = 7)or(q=4) then begin  k:=k+q*e; e:=e*10; end;
       end;
      if k = b then begin writeln(C); exit; end;
    end;

 end.

var s,s1:string;
    n,i,k,k1,k2,k4,k7,min:longint;
begin
 readln(s,s1);
 n:=length(s);
 for i:=1 to n do
  begin
   if (s[i]='7')and(s1[i]='4') then k7:=k7+1;
   if (s[i]='4')and(s1[i]='7') then k4:=k4+1;
  end;
 if k7<=k4 then min:=k7
  else min:=k4;
 k:=min;
 k1:=k7-k;
 k2:=k4-k;
 k:=k+k1+k2;
 writeln(k+1);
end.

var
a,b,c,d,k:longint;
begin
read(a,b);
if a=b then
begin
write(a);
halt;
end;
c:=a; if c<>b then
while d<>b do
begin
a:=a+1;
c:=a;
d:=0;
k:=1;
while c>0 do
begin
if (c MOD 10 = 4) or (C MOD 10 = 7)
then begin
d:=(c Mod 10)*k +d;
k:=k*10;
end;
c:=c DIV 10
end;
end;
write(a);
end.

var n,st1,max,a,b,st:int64;
i:longint;
s:string;
begin                     {
  assign(input,'input.txt');
  reset(input);
  assign(output,'output.txt');
  rewrite(output);       }
  readln(a,b);
  if a<b then begin write(b);halt;end;
  str(b,s);
  st:=1;
  for i:=1 to 6-length(s) do st:=st*10;
  st1:=1;
  for i:=1 to length(s) do st1:=st1*10;
  max:=maxlongint;
  for i:=1 to st do
            if (i*st1+b>a)and(i*st1+b<max) then max:=i*st1+b;
  write(max);
end.

var a,b:longint;
    st1,st2:string;
    i,x,x1,x2,q:longint;
    code:integer;
begin
  readln(a,b);
  str(a,st1);
  str(b,st2);
  if (length(st1)>length(st2))
  then
  begin
    for i:=length(st1)-length(st2)+1 downto 1 do
    begin
      val(st1[i],x1,code);
      val(st2[1],x2,code);
      if x2>=x1
      then
      begin
        q:=0;
        while (x2=x1) and (i+q+1<=length(st1)) do
        begin
          inc(q);
          val(st1[i+q],x1,code);
          val(st2[1+q],x2,code);
        end;
        if x2>x1
        then
        begin
          q:=0;
          while i+q<=length(st1) do
          begin
            st1[i+q]:=st2[1+q];
            inc(q);
          end;
          writeln(st1);
          break;
        end;
      end;
    end;
  end
  else writeln(b);
end.

program z_B;

{$APPTYPE CONSOLE}

uses
  SysUtils;

//type

var
  a,b:integer;
  i:integer;
  flag:boolean;
  t,s:string;

begin
  {assign(input,'input.txt');
  assign(output,'output.txt');}
  readln(a,b);
  if a<=b then write(b)
    else
      begin
      while not flag do
        begin
          inc(a);
          t:=inttostr(a);
          s:='';
          for i:=1 to length(t) do if (t[i]='4') or (t[i]='7') then s:=s+t[i];
          if s=inttostr(b) then flag:=true;
        end;
      write(a);
      end;
end.

var
 i,j,n,m,k,kol,res:longint;
 ans,sa,sb,s:string;
 f1,f2:integer;
begin
{ assign(input,'input.txt');
 reset(input);
 assign(output,'output.txt');
 rewrite(output);  }
 readln(n,m);
 str(m,sb);
 while true do
 begin
  str(n,sa);
  for i:=1 to length(sa) do if (sa[i]<>'4')and(sa[i]<>'7') then delete(sa,i,1);
  if sa=sb then break;
  inc(n);
 end;
 writeln(n);
end.

var
a,b,i,j:longint;
s,ss:string;
begin
readln(a,b);
str(a,s);
str(b,ss);
if length(s)<=length(ss) then writeln(ss)
else begin
i:=1;
for j:=1 to length(s) do begin
    if s[j]>=ss[i] then begin
        s[j]:=ss[i];
        inc(i);
    end;
end;
for j:=1 to length(s)-length(ss) do write(s[j]);
for j:=i to length(ss) do write(ss[j]);
end;
end.

const
    finp='';
    fout='';
var a,b,KQ:string;
    x,y,i,x1:longint;
    f,g:text;
begin
    assign(f,finp); reset(f);
    assign(g,fout); rewrite(g);
    read(f,x,y);
    str(y,b);
    x1:=x;
    dec(x);
    repeat
        inc(x);
        str(x,a);
        for i:=1 to length(a) do
            if (a[i]<>'4') and (a[i]<>'7') then
                delete(a,i,1);
    until (a=b) and (x>x1);
    str(x,KQ);
    write(g,KQ);
    close(f); close(g);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var i,a,b:integer;

function mask(S:string):string;
var x:string;
    i:integer;
begin
for i:=1 to length(s) do
 if (s[i]='4') or (s[i]='7') then x:=x+s[i];
mask:=x;
end;

begin
readln(a,b);
for i:=a to 1000000 do
 if mask(inttostr(i))=inttostr(b) then begin write(i); readln; halt; end;

end.

{$APPTYPE CONSOLE}

var
a,b,k,d,ans,i,t : longint;
begin
 readln (a,b);
 if b>a then
 begin
  writeln (b);
  exit;
 end;

 k:=0;
 d:=b;
 while d<>0 do
 begin
  inc (k);
  d:=d div 10;
  end;

 d:=1;
 for i:=1 to k do d:=d*10;

 t:=a mod d;
 ans:=a div d;

 if t<b then ans:=ans*d+b
        else ans:=(ans+1)*d+b;

 writeln (ans);
end.

var s1,s:string;
    a,b,x,i,c:longint; z:integer;
begin
readln(a,b);
for c:=a+1 to 100000 do begin x:=c; s1:='';
str(x,s);
for i:=1 to length(s) do if (s[i]='4') or (s[i]='7') then s1:=s1+s[i];
val(s1,x,z); if x=b then break; end;
writeln(x);
end.

Var a,b,z,f:Longint;
 Begin
  Read(a,b);
  f:=1;
  If b>a then write(b)
  else begin
  while z<a do
   begin
    f:=f*10;
    z:=f+b;
   end;
  write(z);
  end;
 End.

var
    a,b,a1,b1,g,g1,i:longint;
begin
readln(a,b);
a1:=a+1;
while a1>0 do
begin
    g:=g+1;
    a1:=a1 div 10;
end;
b1:=b;
while b1>0 do
begin
    g1:=g1+1;
    b1:=b1 div 10;
end;
for i:=1 to g-g1 do
    write(1);
write(b);
end.

const fin='';
var f:text;
     a,b:longint;
function kt(a:longint):boolean;
var i,k,d,j:integer;
     s1:string;
begin
     str(a,s1); k:=1; d:=0;
     for i:=1 to length(s1) do
          if (s1[i]<>'4') and (s1[i]<>'7') then delete(s1,i,1);
     val(s1,k,j);
     kt:=k=b;
end;
begin
     assign(f,fin); reset(f);
     read(f,a,b);
     repeat
          inc(a);
     until kt(a);
     write(a);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var tmp,b,i:integer;
  mask,a:string;
begin
  readln(tmp,b);
  a:=IntToStr(tmp);
  mask:='';
  for i:=1 to length(a) do
    if a[i] in ['4','7'] then
      mask:=mask+a[i];
  if mask='' then mask:='1';
  while (StrToInt(mask)<>b) do
    begin
      mask:='';
      a:=IntToStr(StrToInt(a)+1);
      for i:=1 to length(a) do
        if a[i] in ['4','7'] then
          mask:=mask+a[i];
      if mask='' then mask:='1';
    end;
  write(a);
end.

Var a,b,t,i,j,t1:LongInt;
 function rec(x,y:LongInt):LongInt;
  Var x1,y1,y2:LongInt;
  begin
    y2:=0;
    y1:=0;
    x1:=x;
    While x1>0 do
      begin
        if (x1 mod 10=4) or (x1 mod 10=7) then y1:=(y1*10)+x1 mod 10;
        x1:=x1 div 10;
      end;
    x1:=y;
    While x1>0 do
      begin
        y2:=y2*10+(x1 mod 10);
        x1:=x1 div 10;
      end;
    if y2=y1 then begin WriteLn(x); halt; end;
  end;
  begin
    ReadLn(a,b);
    if b>a then begin WriteLn(b); exit; end;
    t:=a;
    While t>0 do
     begin
       i:=i+1;
       t:=t div 10;
     end;
    t1:=0;
    t:=1;
    For j:=2 to i do
        t:=t*10;
    While 2<>0 do
     begin
       t1:=t1+t;
       if t1+b>a then begin rec(t1+b,b); end;
     end;
  end.

var
a,b:integer;

function pp(a1:integer):integer;
var m,mask,st:integer;
begin
mask:=0; st:=1;
while a1<>0 do
begin m:= a1 mod 10;
if (m=7) or (m=4) then begin mask:=mask+m*st; st:=st*10; end;
a1:=a1 div 10;
end;
pp:=mask;
end;
begin
read(a,b);
writeln;
while pp(a)<>b do inc(a);
writeln(a);
end.

var s1,s,mm,ss:string;
n,m,i,lik,a,b:longint;
begin
readln(n,m);
str(m,mm);
for i:=length(mm) downto 1 do
ss:=ss+mm[i];
for i:=n to 100000 do
begin
 a:=i;
 s:='';
 while a<>0 do
   begin
   b:=a mod 10;
   str(b,s1);
   if (s1='4')or(s1='7') then  s:=s+s1;
   if s=ss then begin writelN(i);halt;end;
   a:=a div 10;

   end;

end;

writeln(s);

end.

var a,b,c,t,x: longint;
begin
    read(a,b);
    if a<b then begin writeln(a); halt end;
    x:=b; t:=1;
    repeat
      x:=x div 10; t:=t*10;
    until x=0;

    c:=b;
    repeat
      c:=c+t;
    until (c>a);
    writeln(c)

end.

var
 s:ansistring;
 n,m,i,z,x,c,ss,d,r:longint;
 l:integer;
begin
 read(n,m);
 for i:=n to 2000000 do
 begin
  x:=i;
  s:='';
  while x<>0 do
  begin
   z:=x mod 10;
   if (z=4)or(z=7)then s:=chr(z+48)+s;
   x:=x div 10;
  end;
  val(s,d,l);
  if d=m then
  begin
   writeln(i);
   halt;
  end;
 end;
end.

Var a,b,c:LongInt;

Function Luck (x:LongInt):LongInt;
Var code,i:Integer;
s:String;
Begin
     Str (x,s);
     i:=1;
     While i<>Length (s)+1 do
     Begin
          If not (s[i] in ['4','7'])
     then Delete (s,i,1)
     else Inc (i);
        Writeln (s);
        End;
     If s=''
     then x:=0
     else Val (s,x,code);
     Luck:=x;
End;

Begin
     Readln (a,b);
     c:=a+1;
     While Luck(c)<>b do
     Inc (c);
     Writeln (c);
End.

var n,i,a,b,x,k:longint;
    p:integer;
    s:string;
begin
  read(a,b);
  x:=a+1;
  k:=x;
  while k<>b do
  begin
    inc(x);
    str(x,s);
    for i:=length(s) downto 1 do if (s[i]<>'4') and (s[i]<>'7') then delete(s,i,1);
    val(s,k,p);
  end;
  writeln(x);
end.

program ConsoleOlympProj;

{$APPTYPE CONSOLE}

function GetMask(Number: Integer): Integer;
var
  Digit, k: Integer;
begin
  Result := 0;
  k := 1;
  while Number > 0 do
  begin
    Digit := Number mod 10;
    if Digit in [4, 7] then
      Result := k * Digit + Result;
    k := k * 10;
    Number := Number div 10;
  end;
end;

var
  a, b: Integer;

begin
{$IFNDEF ONLINE_JUDGE}
  Assign(Input, 'input.txt');
  Reset(Input);
  Assign(Output, 'output.txt');
  Rewrite(Output);
{$ENDIF}

  ReadLn(a, b);

  if a < b then
    Write(b)
  else
  begin
    repeat
      Inc(a);
    until GetMask(a) = b;
    Write(a);
  end;

{$IFNDEF ONLINE_JUDGE}
  Close(Input);
  Close(Output);
{$ENDIF}
end.

{$APPTYPE CONSOLE}
var
  a,b,n,i: longint;
  mask: array[0..9] of integer;

  function check(x: longint): boolean;
  var
    m,y: longint;
  begin
    m:=0;
    while x>0 do
    begin
      y:=x mod 10;
      if y in [4,7] then
      begin
        inc(m);
        if y<>mask[m] then
        begin
          check:=false;
          exit;
        end;
      end;
      x:=x div 10;
    end;
    if m<>n then
    begin
      check:=false;
      exit;
    end;
    check:=true;
  end;

begin
  read(a,b);
  n:=0;
  while b>0 do
  begin
    n:=n+1;
    mask[n]:=b mod 10;
    b:=b div 10;
  end;
  for i:=a to 1000000 do
  if check(i) then
  begin
    write(i);
    break;
  end;
//  readln; readln;
end.

var a,b,i,j:longint;
    found:boolean;
function mask(a:longint):longint;
var x,k,c:longint;
begin
    c:=a;
    x:=1;
    k:=0;
    while c>0 do begin
        if (c mod 10=4)or(c mod 10=7) then begin
            k:=k+(c mod 10)*x;
            x:=x*10;
        end;
        c:=c div 10;
    end;
    mask:=k;
end;
begin
    readln(a,b);
    while mask(a)<>b do
        inc(a);
    writeln(a);
    readln;
end.

uses sysutils;
var
  A,B,C:longint;
function getMask(a:longint):longint;
var
  s:string;
  i:byte;
  res:longint;
begin
  s:=IntToStr(a);
  res:=0;
  for i := 1 to length(s) do
    if s[i] in ['7','4']
      then
        res:=res*10+ord(s[i])-48;

  getMask:=res;
end;
begin

  read(A,B);
  if B<A then C:=B else
  for C:=A to 100000 do
    if getMask(C)=B
      then
        break;

  writeln(C);
end.

var
 t1,t2,t:string;
 razn,sum1,sum2,n,n1,n2,i,kl:longint;
 fl:boolean;
 a,b:Array[0..1000]of longint;
 ind:array[0..100]of longint;

Begin
  //assign(input,'input.txt');reset(input);
 // assign(output,'output.txt');rewrite(output);
  readln(t);
  n:=length(t);
  i:=1;
  while t[i]<>' ' do
   begin
    t1:=t1+t[i];
    inc(i);
   end;

 while i<=n do
  begin
    t2:=t2+t[i];
    inc(i);
  end;
  delete(t2,1,1);
  n1:=length(t1);n2:=length(t2);

  razn:=abs(n2-n1);
  for i:=1 to razn do
   write(t1[i]);

  for i:=1 to n2 do
   write(t2[i]);

// close(input);close(output);
End.

{$mode objfpc}
{-$S-, Q-, R-, I-, O+}
{$S+, Q+, R+, I+, O+}
uses sysutils;
var
  a, b, c : longint;
  s1, s2, s3 : string;
begin
  readln(a, b);
  s1 := inttostr(a);
  s2 := inttostr(b);
  if b>a then
    c := b
  else
  begin
    if length(s1) = length(s2) then
      c := length(s1) * 10 + b
    else
    begin
      s3 := copy(s1, 1, length(s1) - length(s2)) + s2;
      c := strtoint(s3);
    end;
  end;
  write(c);
end.

var a,b,x,c,p,r:int64;
    i:longint;
begin
  readln(a,b);
  for i:=a+1 to 1000000 do
   begin
     x:=i;
     p:=1;
     c:=0;
     r:=0;
     while x<>0 do
      begin
        if (x mod 10 = 7) or (x mod 10=4) then c:=c+p*(x mod 10);
        r:=r+p*(x mod 10);
        x:=x div 10;
        p:=p*10;
      end;
     if c=b then break;
   end;
  writeln(r);
end.

var a,b,c,i,k,aa:longint;
    x:array[1..10]of integer;

begin
 read(a,b);
 if a<=b then write(b) else begin
 while true do
  begin
   k:=0;
   c:=0;
   aa:=a;
   while a>0 do
    begin
     if a mod 10= 4 then begin inc(k);x[k]:=4; end;
     if a mod 10= 7 then begin inc(k);x[k]:=7; end;
     a:=a div 10;
    end;
   for i:=k downto 1 do
    c:=c*10+x[i];
   if c=b then begin writeln(aa);break; end;
   a:=aa;
   inc(a);

  end;
 end;
end.

var s1,s:string;
    a,b,x,i,c:longint; z:integer;
begin
readln(a,b);
if a>77777 then exit;
for c:=a+1 to 100000 do begin x:=c; s1:='';
str(x,s);
for i:=1 to length(s) do if (s[i]='4') or (s[i]='7') then s1:=s1+s[i];
val(s1,x,z); if x=b then break; end;
writeln(c);
end.

var a,b,x:longint;
function mask (a:longint):longint;
 var x,k:longint;
 begin
 while a>0 do
  begin
  if (a mod 10=4) or (a mod 10=7) then x:=(x*10)+(a mod 10);
  a:=a div 10;
  end;
 while x>0 do
  begin
  k:=(k*10)+(x mod 10);
  x:=x div 10;
  end;
 mask:=k;
 end;
begin
readln(a,b);
x:=a;
while mask(x)<>b do
 inc(x);
write(x);
end.

uses sysutils;
var
  A,B,C:longint;
function getMask(a:longint):longint;
var
  s:string;
  i:byte;
  res:longint;
begin
  s:=IntToStr(a);
  res:=0;
  for i := 1 to length(s) do
    if s[i] in ['7','4']
      then
        res:=res*10+ord(s[i])-48;

  getMask:=res;
end;
begin

  read(A,B);
  if B>A then C:=B else
  for C:=A+1 to 100000 do
    if getMask(C)=B
      then
        break;

  writeln(C);
end.

var
    a,b,i:longint;

function numoff(x:longint):longint;
var
    i,ans:longint;
    tmp:string;
begin
    str(x,tmp);
    for i:=1 to length(tmp) do
    if (tmp[i]<>'4')and(tmp[i]<>'7') then delete(tmp,i,1);
    val(tmp,ans);
    exit(ans);
end;

begin
    readln(a,b);
    for i:=a+1 to 1000000 do
    if numoff(i)=b then
    begin
        writeln(i);
        halt;
    end;
end.
//By THCDUSMAN

var
a,b,i,j:longint;
s,ss:string;
begin
readln(a,b);
str(a,s);
str(b,ss);
if length(s)<=length(ss) then writeln(ss)
else begin
i:=1;
for j:=1 to length(s) do begin
    if s[j]>=ss[i] then begin
        s[j]:=ss[i];
        inc(i);
    end;
    if i=length(ss)+1 then break;
end;
for j:=1 to length(s)-length(ss) do write(s[j]);
if i<=length(ss) then
for j:=i to length(ss) do write(ss[j]);
end;
end.

var bb,a,b,i:longint;

function f(a,i:longint):longint;
var k,aa,s:longint;
begin
k:=0;
aa:=a;
while aa<>0 do begin
aa:=aa div 10;
inc(k);
end;
k:=k+i;
s:=round(exp(ln(10)*k));
f:=a+s;
end;

begin
read(a,b);
bb:=b;
i:=0;
while bb<=a do begin
bb:=f(b,i);
inc(i);
end;
write(bb);
end.

var n:longint;s,aa,bb:string;x,i,f,a,b:longint;
begin         {
assign (input,'input.txt');
assign (output,'output.txt');
reset (input);
rewrite (output);  }
readln (a,b);
if a<b then begin write (b);halt;end;
str (a,aa);
str (b,bb);
bb:='1'+bb;
n:=length(bb)-1;
while length(aa)>length(bb) do begin insert ('0',bb,2);end;
if length(bb)>length(Aa) then begin write (bb);halt;end;
for i:=1 to length (aa)-n do
  if (aa[i]>bb[i]) then begin bb[i]:=aa[i];break end else if aa[i]<bb[i] then break;
f:=0;
for i:=length(aa)-n+1 to length(aa) do
  begin
    if aa[i]>bb[i] then begin f:=1;break;end else
    if aa[i]<bb[i] then begin f:=-1;break;end;
  end;
if f<>-1 then
  begin
    for i:=length(aa)-n downto 1 do
      if aa[i]<>'9' then begin bb[i]:=chr (ord(aa[i])+1);f:=-1;break;end;
    if f<>-1 then
      begin
        for i:=length(aa)-n downto 1 do bb[i]:='0';
        bb:='1'+bb;
      end;
  end;

write (bb);
end.

var a,b,i,j:longint;
    a1,b1:string;
begin
 readln(a,b);
 if a<b then begin writeln(b);exit;end;
 str(b,b1);
 for i:=a+1 to 77777 do begin
   str(i,a1);
    j:=1;
    while j<=length(a1) do
      if (a1[j]<>'4') and (a1[j]<>'7') then delete(a1,j,1) else j:=j+1;
    if b1=a1 then break;end;
 writeln(i);
end.

var
a,b,c,i,k:longint;
s,st:string;
procedure check;
var stt:string;
begin
stt:='';
str(a,s);
for i:=1 to length(s) do
if (s[i]='4')or(s[i]='7') then stt:=stt+s[i];
if stt=st then begin
if k=a then exit;
writeln(a);
halt
end;
end;

begin
readln(a,b);k:=a;
if a<b then
  begin
  writeln(b);
  exit;
  end;
str(b,st);

while (a mod 10<>4)and(a mod 10<>7) do inc(a);
while true do
   begin
    check;
	if a mod 10=4 then inc(a,3)
	else inc(a,7);
	end;
end.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q+,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
//{$A8,B-,C+,D-,E-,F-,G+,H+,I-,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}

program ProblemB;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

const
  inname = 'input.txt';
  outname = 'output.txt';
  maxn = 0;
  maxm = 0;
  inf = maxlongint div 2;
  eps = 0;

type
  int = longint;
  bool = boolean;
  real = extended;

var
  a, b: int;

function m(a: int): int;
var
  k, d, t: int;
begin
  d := 10000000;
  while d > a do
    d := d div 10;

  t := 0;
  while a > 0 do begin
    k := a div d;
    if (k = 4) or (k = 7) then
      t := 10 * t + k;
    a := a mod d;
    d := d div 10;
  end;

  result := t;
end;

procedure run;
begin
  read(a, b);

  while m(a) <> b do
    inc(a);

  write(a);
end;

procedure openfiles;
begin
  assign(input, inname);
  assign(output, outname);
  reset(input);
  rewrite(output);
end;

procedure closefiles;
begin
  close(input);
  close(output);
end;

Begin
  //openfiles;
  run;
  //closefiles;
End.