// Arup Guha
// 11/16/2014
// Solution to 2014 South East Regional D1 and D2 Problem: Hill Numbers

import java.util.*;

public class hillnumbers {

	public static String numStr;
	public static long number;
	public static long[][][] memo;

	public static void main(String[] args) {

		// Read in input.
		Scanner stdin = new Scanner(System.in);
		numStr = stdin.next();
		number = Long.parseLong(numStr);
		int n = numStr.length();

		// Simple case.
		if (!hill(numStr)) System.out.println(-1);

		else {

			int down = getDown(numStr);
			memo = new long[n+1][10][2];

			// Fill memo table - all uninitialized.
			for (int i=0; i<=n; i++)
				for (int j=0; j<10; j++)
						Arrays.fill(memo[i][j], -1);

			// Count all strings less than length of number.
			long ans = 0;

			// Now iterate through all numbers of the proper length
			for (int i=0; i<numStr.length(); i++) {

				int start = i > 0 ? numStr.charAt(i-1)-'0':0;
				int end = numStr.charAt(i)-'0';

				// Put in this digit going up, if possible.
				if (i < down) {

					// Putting smaller digits in the msb.
					for (int j=start; j<end; j++)
						ans += countStrings(n-i-1, j, true);

					// Start a streak going down, all will be counted here.
					for (int j=start-1; j>=0; j--)
						ans += countStrings(n-i-1, j, false);
				}

				// On way down, try each possible digit in this slot.
				else {
					for (int j=end-1; j>=0; j--)
						ans += countStrings(n-i-1, j, false);
				}
			}

			// Output the result counting the number itself.
			System.out.println(ans+1);
		}

	}

	// n = number of digits
	// prevValue = the previous digit we're building off of.
	// returns total number of strings satisfying these constraints.
	public static long countStrings(int n, int prevValue, boolean up) {

		// Avoid crashing.
		if (prevValue < 0) return 0;

		int upVal = up ? 1:0;

		// Whole number filled in - but don't count 0.
		if (n == 0) {
			if (prevValue == 0 && up) return 0;
			return 1;
		}

		// Look up memo table.
		if (memo[n][prevValue][upVal] != -1) return memo[n][prevValue][upVal];

		long sum = 0;

		// Can still go up, so split work into two cases.
		if (up) {
			for (int i=prevValue; i<10; i++)
				sum += countStrings(n-1, i, true);
			for (int i=prevValue-1; i>=0; i--)
				sum += countStrings(n-1, i, false);
		}

		// Can only go down.
		else {
			for (int i=prevValue; i>=0; i--)
				sum += countStrings(n-1, i, false);
		}

		// Store and return.
		memo[n][prevValue][upVal] = sum;
		return sum;
	}

	// Returns first index, i, where n[i] > n[i+1].
	public static int getDown(String num) {
		int i;
		for (i=0; i<num.length()-1; i++)
			if (num.charAt(i) > num.charAt(i+1))
				return i+1;
		return num.length();
	}

	public static boolean hill(String num) {

		// Go up.
		int i;
		for (i=0; i<num.length()-1; i++)
			if (num.charAt(i) > num.charAt(i+1))
				break;

		// Come down.
		while (i<num.length()-1) {
			if (num.charAt(i) < num.charAt(i+1))
				return false;
			i++;
		}

		// Made it!
		return true;
	}
}