import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class F_特别数的和 {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
static String [] str;
static int N = 10010,n,res;
public static void main(String[] args) throws NumberFormatException, IOException {
n = Integer.parseInt(reader.readLine());
for (int i = 1; i <= n; i++) {
if(find(i)) res += i;
}
System.out.println(res);
}
public static boolean find(int x) {
String t = String.valueOf(x);
if(t.indexOf("2")!=-1||t.indexOf("0")!=-1||t.indexOf("1")!=-1||t.indexOf("9")!=-1) return true;
else return false;
}
}