#include <bits/stdc++.h>
using namespace std;
int ans = 0,T;
void dfs(long long x,bool a,bool b,bool c) //a,b,c´ú±í7,5,3³öÏÖµÄ±êÖ¾Î» 
{//dfsÃ¶¾ÙËùÓÐ´øÓÐ357µÄÊý×é£¬Ê±¼ä¸´ÔÓ¶È3^10 
	 if(x > T) return;
	 if(a&&b&&c) ans++;
	 x *= 10;
	 dfs(x+7,true,b,c);
	 dfs(x+5,a,true,c);
	 dfs(x+3,a,b,true);
}
int main() {
	cin>>T;
	dfs(0,0,0,0);
	cout<<ans;
	return 0;
}