var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var arr = [-1];
	var pow3 = [1];
	for(var i = 1 ; i < 11; i++){
		pow3[i] = 3*pow3[i-1];
	}
	var M = 1000000000;
	var a,b,c;
	var ans = 0;
	var arr357 = [3,5,7];
	for(var i = 0; i < M; i++){
		a = i;
		arr[0]++;
		for(var j = 0; j < 10; j++){
			if(arr[j]===3){
				arr[j]-=3;
				if(arr[j+1]===undefined){
					arr[j+1] = 0;
					break;
				}else{
					arr[j+1]++;
				}
			}

		}
		c = arr.map(el=>arr357[el]);
		//console.log(i,arr,c)
		if(toInt(c.reverse().join(''))>n){
			break;
		}
		if(arr.indexOf(0)===-1 || arr.indexOf(1)===-1 || arr.indexOf(2)===-1){
			continue;
		}
		ans++;

	}
	console.log(ans);
}