{$N+}

const
  NMAX = 17;

var
  N,d,i: Integer;
  res,f: Comp;

(*find position of number of k digits d*)
function findpos(f:Comp):Comp;
var
  p,q,ps: Comp;
  i,r: Integer;
begin

  p:=0;
  q:=9;
  r:=1;
  ps:=0;
  while p+q<f do
  begin
   ps:=ps+q*r;
   p:=p+q;
   q:=q*10;
   inc(r);
  end;
  ps:=ps+r*(f-p);
  findpos := ps - r + 1;
end;

procedure out(x:Comp);
var
  q:array[1..100] of Byte;
  i,j: Integer;
  r: Byte;
begin
  if x=0 then begin writeln('0'); exit; end;
  i:=0;
  while x>0 do
  begin
    inc(i);
    r:=Round(x - Int(x/10)*10);
    q[i]:=r;
    x:=Int(x/10);
  end;
  for j:=i downto 1 do write(q[j]);
  writeln;
end;


begin
//  assign(input,'input.txt');
//  reset(input);
//  assign(output,'output.txt');
//  rewrite(output);
   
  readln(N,d);

  if N=1 then
  begin
    if d>0 then writeln(d) else writeln(11);
    exit;
  end;

  if d=0 then
  begin
    f:=0;
    for i:=1 to N do f:=f*10+9;
    res := findpos(f)+N+1;
  end else
  if d<9 then
  begin (* 1-8 *)
    f:=0;
    for i:=1 to trunc(N/2)+1 do f:=f*10+d;
    res := findpos(f);
  end else
  begin (* d=9 *)
    f:=8;
    for i:=1 to N-1 do f:=f*10+9;
    res := findpos(f)+1;
  end;

  out(res);

end.
