import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } static long N; static long FACTOR = 1_000_000_000 + 1; static long[] pow10 = new long[19]; void run() { pow10[0] = 1; for (int i = 1; i < pow10.length; ++i) pow10[i] = pow10[i - 1] * 10; Scanner sc = new Scanner(System.in); N = sc.nextLong(); long ans = 0; for (int i = 0; i <= 8; ++i) { ans += dfs(0, i, 0, true); } System.out.println(ans); } static long dfs(int s, int t, long cur, boolean f) { if (s > t) { if (cur > 0) { return 1; } else return 0; } long sum = 0; for (int i = (f ? 1 : 0); i < 10; ++i) { long tmp = cur + (pow10[s] + (s == t ? 0 : pow10[t])) * i; if (tmp * FACTOR <= N) { sum += dfs(s + 1, t - 1, tmp, false); } } return sum; } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }