#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0; i #define VP vector> #define VPP vector>> #define VLL vector #define VVI vector> #define VVLL vector> #define VC vector #define VS vector #define VVC vector> #define VB vector #define VVB vector> #define fore(i,a) for(auto &i:a) typedef pair P; template using min_priority_queue = priority_queue, greater>; template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1 << 29; const ll INFL = 1LL << 60; const ll mod = 998244353; int ans = 0; ll n; void dfs(ll a) { if (10 <= a && a <= n) { ans++; } if (a > n)return; dfs(a * 10); dfs(a * 10 + 3); dfs(a * 10 + 6); dfs(a * 10 + 9); } int main(){ cin >> n; FOR(i, 10, min(100, (int)n + 1)) { if (((i % 10) + (i / 10)) % 3 == 0) { if ((i % 10) % 3 != 0 && (i / 10) % 3 != 0) { if (i % 3 == 0) { ans++; } } } } dfs(3); dfs(6); dfs(9); cout << ans << endl; }