def f(n):
    x = [int(d) for d in str(n)]
    flg = True
    dp = 0
    for d in x:
        dp = ((dp * 8) + (flg * count(d)))
        if (d in ng):
            flg = False
    return (n - (dp + flg))
def f(n):
    x = [int(d) for d in str(n)]
    flg = True
    dp = 0
    for d in x:
        dp = ((dp * 8) + (flg * count(d)))
        if (d in ng):
            flg = False
    return (n - (dp + flg))