#include using namespace std; using ll = long long; template using vec = vector; template using vvec = vector>; template using vvvec = vector>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int ans = 0; for(int i=10;i<=min(N,99);i++){ if(i%3==0){ int c = i/10%3+i%10; if(c%3==0) ans++; } } if(N<100){ cout << ans << "\n"; return 0; } set s; auto dfs = [&](auto&& self,ll n)->void{ if(n%3==0 && n>=100) s.insert(n); for(auto& x:{0,3,6,9}){ if(10*n+x<=N) self(self,10*n+x); } }; for(auto& x:{3,6,9}) dfs(dfs,x); ans += s.size(); cout << ans << "\n"; }