import itertools
def calc_num(S,S_len):
    result = 0;
    l = [3,5,7];
    i = 3;
    while i <= S_len:
      for v in itertools.product(l,repeat=i):
        if int("".join(map(str, v))) >= S: 
          break;
        if list(set(v) & set(l)) == l: 
          result = result + 1;
      i = i + 1;
    return result
  
S = list(map(int,input()))
S_len = len(S);
S = int("".join(map(str, S)));
result = calc_num(S,S_len);
print(result)