program Project1;
var
  v,x,k,i,y,c,z,q:longint;

  d:array[1..3] of integer;
begin
  readln(v);
  d[1]:=1;
  d[2]:=2;
  d[3]:=5;
  x:=0;
  y:=10;
  while v>0 do
  begin
  q:=v;
  while q>1 do
  begin
  q:=q div 10;
  c:=c+1;
  end;
  k:=c-1;
  for i:=1 to k do
  y:=y*10;
  for i:=1 to 3 do
  begin
  z:=d[i]*y;
  if v>z then x:=x+1;
  end;
  if v-z<=0 then
  writeln(x);
  readln;
  end;

end.