#include <iostream>
using namespace std;

#define ll unsigned long long

int main() {
	ll n;
	cin >> n;
    ll x1 = n, cnt = 0;
//    Считаем количество цифр
    while (x1) x1 /= 10, cnt++;
    int d[cnt], i = 1;
    x1 = n;
//    Заполняем массив цифр
    while (x1) d[cnt - i++] = x1 % 10, x1 /= 10;
//    Заменяем цифры после 8 на 799999...
    bool f = false;
    for (int i = 0; i < cnt; i++)
        if (f)
            d[i] = 9;
        else if (d[i] == 8)
            d[i] = 7, f = true;
//    Считаем степени девятки
    ll pow9[19];
    pow9[0] = 1;
    for (int i = 1; i <= 18; i++)
        pow9[i] = pow9[i - 1] * 9;
//    Считаем ответ
    ll res = 0;
    for (int i = cnt - 1; i >= 0; i--)
        res += pow9[cnt - i - 1] * (d[i] - (d[i] >= 8));
    cout << res <<endl;
}
