One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.

But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.

Input

Input data contains the only number n (1 ≤ n ≤ 109).

Output

Output the only number — answer to the problem.

Examples

Input

10


Output

2

Note

For n = 10 the answer includes numbers 1 and 10.
from math import *

def myinc(n):
    l = list(str(n))
    l.reverse()
    i = 0
    while (i < len(l)) and (l[i] == '1'):
        i += 1
    if i == len(l):
        return 10**len(l)
    else:
        l[i] = '1'
        for j in range(i):
            l[j] = '0'
        res = 0
        for i in range(len(l)):
            res += int(l[i])*10**i
        return res
    


n = int(raw_input())
c = 0
i = 1
while i <= n:
    c += 1
    i = myinc(i)
print(c)

"""l = [5,3,4]
print(BIS(l))"""



"""from math import *
from Queue import *

def bfs(G, start):
    visited = set([start])
    Q = Queue()
    Ret = [start]
    Q.put(start)
    while not Q.empty():
        vertex = Q.get()
        for v in G[1][vertex]:
            if v not in visited:
                Q.put(v)
                visited.add(v)
                Ret.append(v)
    return Ret

def longest_path(G):
    l = bfs(G,G[0][0])
    marked = set()
    result = dict()
    for i in l:
        result[i] = [0,i,0,i]
    for i in range(len(l)-1, -1, -1):
        for j in G[1][l[i]]:
            if j in marked:
                if (result[j][2] > result[l[i]][2]) or ((result[j][2] == result[l[i]][2]) and (result[j][3] < result[l[i]][3])):
                    result[l[i]][2] = result[j][2]
                    result[l[i]][3] = result[j][3]
                if (result[l[i]][0] + result[j][0] + 1 > result[l[i]][2]):
                    result[l[i]][2] = result[l[i]][0] + result[j][0] + 1
                    result[l[i]][3] = min(result[l[i]][1], result[j][1])
                if ((result[l[i]][0] + result[j][0] + 1 == result[l[i]][2]) and (min(result[l[i]][1],result[j][1]) < result[l[i]][3])):
                    result[l[i]][3] = min(result[l[i]][1],result[j][1])
                if (result[j][0] + 1 > result[l[i]][0]) or ((result[j][0] + 1 == result[l[i]][0]) and (result[j][1] < result[l[i]][1])):
                    result[l[i]][0] = result[j][0] + 1
                    result[l[i]][1] = result[j][1]
        marked.add(l[i])
    return (result[l[0]][2], result[l[0]][3])

def remove(G,v):
    ver = G[0]
    ver.remove(v)
    edg = dict()
    for i in ver:
        nb = []
        for j in G[1][i]:
            if j != v:
                nb.append(j)
        edg[i] = nb
    return (ver, edg)

def harvest(G,M):
    l = bfs(G,M[0])
    seen = set()
    delete = []
    for i in range(len(l)-1, -1, -1):
        seen.add(l[i])
        if l[i] in M:
            for j in G[1][l[i]]:
                if j not in seen:
                    M.append(j)
        if l[i] not in M:
            delete.append(l[i])
    for i in delete:
        G = remove(G,i)
    return G

s = raw_input()
l = s.split(' ')
n = int(l[0])
m = int(l[1])
V = []
Adj = [[] for i in range(n+1)]
for i in range(1,n+1):
    V.append(i)
E = dict()
for i in range(n-1):
    s = raw_input()
    l = s.split(' ')
    h = int(l[0])
    t = int(l[1])
    Adj[h].append(t)
    Adj[t].append(h)
E = dict()
for i in range(1, n+1):
    E[i] = Adj[i]
G = [V,E]
s = raw_input()
l = s.split(' ')
M = []
for i in range(m):
    M.append(int(l[i]))
G = harvest(G,M)
sol = longest_path(G)
print(sol[1])
print(2*len(G[0]) - 2 - sol[0])"""
