#include using namespace std; using lint = long long; lint n; int ans = 0; void dfs(lint cur) { if (cur > n) return; if (cur > 100) ans++; 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) { ans++; } // 3桁以上の場合 dfs(3); dfs(6); dfs(9); cout << ans << endl; return 0; }