function main(arg) {
	arg = Number(arg.split("\n")[0])

	var master = [0, 3,5,7]
	var counter = 0;

	for (var i = 0;;i++) {
		var tmp = String(i.toString(4))
		var _tmp = "";

		if (tmp.length < 3) {
			continue;
		}

		if (tmp.indexOf('0') !== -1) {
			continue;
		}

		var b = tmp.split("").filter(function (x, i, self) {
            return self.indexOf(x) === i;
        });

		if (b.length < 3) {
			continue;
		}


		for (var j = 0; j < tmp.length; j++) {
			_tmp += master[tmp[j]]
		}

		if (_tmp > arg) {
			break;
		}
		counter++
	}
	console.log(counter)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));