#include using namespace std; int main() { int n; cin >> n; int k = 0; while(n >= pow(10, k + 1)) k++; cout << 9 * (k + 2) << endl; }