#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, ans = 0;
cin >> n;
for(int i = 1; i <= n; i++)
{
int cur = i;
int sum = 0;
while(cur)
{
sum += cur % 10;
cur /= 10;
}
bool ok = true;
while(sum)
{
int l = sum % 10;
ok &= l == 4 || l == 7;
sum /= 10;
}
ans += ok;
}
cout << ans << "\n";
return 0;
}