#include using namespace std; using ll = long long; #define rep(i,m,n) for(int i=m; i bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; } template bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; } template T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; } template T lcm(T a, T b){ return a / gcd(a, b) * b; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; set st; for(ll i = 12LL; i <= min(100LL, N); i += 3LL){ string s = to_string(i); if(((s[0] - '0') + (s[1] - '0')) % 3 == 0) st.insert(i); } auto rec = [&](auto rec, ll x) -> void { if(x > N) return; if(x >= 10LL) st.insert(x); if(x) rec(rec, x*10LL + 0LL); rec(rec, x*10LL + 3LL); rec(rec, x*10LL + 6LL); rec(rec, x*10LL + 9LL); }; rec(rec, 0LL); // for(ll s : st) cout << s << endl; cout << st.size() << endl; return 0; }