# include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

long long n, ans;

int len(long long x){
      int cnt = 0;
      while(x){
            cnt ++;
            x /= 10;
      }
      return cnt;
}

int fir(long long x){
      while(x > 9){
            x /= 10;
      }
      return x;
}

int main(){
      cin >> n;

      ans = (len(n) - 1) * 9 + fir(n) - 1;

      int cnt = 0;

      while(n){
            if(n % 10 != 9) cnt ++;
            n /= 10;
      }

      if(cnt == 0) ans = max(ans, len(n) * 1ll  * 9);

      cout << ans << endl;
}
