def f4(n):
  s=0
  d=1
  q=0
  while n>0:
    s+=d*(n%4)
    d*=10
    n=n//4
  return s

n=input()
d=len(n)
if d>3 and n[0:2] in ['11','12','21','22']:
  d-=1
  n='7'*d
ans=0
m=''
for i in range(d):
  x=n[i]
  if x in '12':
    m+='0'
  elif x in '34':
    m+='1'
  elif x in '56':
    m+='2'
  else:
    m+='3'
for i in range(1,1+int(m,4)):
  l=[x for x in str(f4(i))]
  l=list(set(l))
  if len(l)==3 and 6==int(l[0])+int(l[1])+int(l[2]):
    ans+=1

print(ans)