#include using namespace std; using lint = long long; lint n; set st; void dfs(lint cur) { if (cur > n) return; if (cur > 100) st.insert(cur); dfs(cur * 10); dfs(cur * 10 + 3); dfs(cur * 10 + 6); dfs(cur * 10 + 9); } int main() { cin >> n; // 2桁の場合 for (lint i = 12; i < 100 and i <= n; i += 3) { st.insert(i); } // 3桁以上の場合 dfs(3); dfs(6); dfs(9); cout << st.size() << endl; return 0; }