// Arup Guha
// 11/30/2017
// Solution? to 2014 SER D1/D2 Problem: Hill Numbers
// Coded live for Programming Team lecture

import java.util.*;

public class hillnumberslec {
	
	public static int[] num;
	public static int n;
	
	public static long[][][][] dp;
	
	public static void main(String[] args) {
		
		// Read in the number (store in array).
		Scanner stdin = new Scanner(System.in);
		String s = stdin.next();
		n = s.length();
		num = new int[n];
		for (int i=0; i<n; i++)
			num[i] = s.charAt(i) - '0';	
				
		// Initialize memo table.
		dp = new long[n][10][2][2];
		for (int i=0; i<n; i++)
			for (int j=0; j<10; j++)
				for (int k=0; k<2; k++)
					Arrays.fill(dp[i][j][k], -1);	
						
		// Ta da!
		System.out.println(solve());
	}
	
	// Wrapper to solve the problem.
	public static long solve() {
		
		// Get rid of these!
		if (!isHill()) return -1;
		
		// Wrapper call...sub out 0.
		return go(0, 0, 1, 1)-1;
	}
	
	// Returns true iff num is a Hill Number.
	public static boolean isHill() {
		int state = 0;
		for (int i=0; i<n-1; i++) {
			if (state == 1 && num[i] < num[i+1]) return false;
			if (state == 0 && num[i] > num[i+1]) state = 1;
		}
		return true;
	}
	
	// k = Digit we're on, last = value of last digit, 
	// up = 1 if going up, 0 = down, equal = 1 if equal, 0 otherwise
	public static long go(int k, int last, int up, int equal) {
		
		// Found a solution!
		if (k == n) return 1;
		
		// Did this already, return answer.
		if (dp[k][last][up][equal] != -1) return dp[k][last][up][equal];
		
		long res = 0;
		
		// Do digits we can only do if we are still going up.
		if (up == 1) {
			
			// i is digit we are filling in next.
			for (int i=last+1; i<10; i++) {
				
				// Can't put i here, makes the number too big.
				if (equal == 1 && i>num[k]) break;
				
				// Cases where we recurse and the number we've built isn't equal.
				if (equal == 0 || i < num[k])
					res += go(k+1, i, up, 0);
				
				// One case where we are still equal.
				else
					res += go(k+1, i, up, 1);
			}
		}
		
		// Now try digit i in this slot, potentially going down.
		for (int i=0; i<=last; i++) {
			
			// Can't put i here, makes the number too big.
			if (equal == 1 && i>num[k]) break;
			
			// What my up/down status will be after adding digit i.
			int newUp = (up == 1 && i == last) ? 1 : 0;
			
			// Cases where we recurse and the number we've built isn't equal.
			if (equal == 0 || i < num[k])
				res += go(k+1, i, newUp, 0);
			
			// We're still equal here.
			else
				res += go(k+1, i, newUp, 1);
		}
		
		// Store and return.
		return dp[k][last][up][equal] = res;
	}
}