Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. 

The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: 

"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"

Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.

Input

The single line contains the magic integer n, 0 ≤ n.

  * to get 20 points, you need to solve the problem with constraints: n ≤ 106 (subproblem C1); 
  * to get 40 points, you need to solve the problem with constraints: n ≤ 1012 (subproblems C1+C2); 
  * to get 100 points, you need to solve the problem with constraints: n ≤ 1018 (subproblems C1+C2+C3). 

Output

Print a single integer — the minimum number of subtractions that turns the magic number to a zero.

Examples

Input

24


Output

5

Note

In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: 

24 → 20 → 18 → 10 → 9 → 0
WaitingList = {}
quickTable = {'5999998': (128206L, 999998L), '5999995': (128206L, 999995L), '29999999999999998': (1141743745619794L, 9999999999999998L), '29999999999999997': (1141743745619794L, 9999999999999997L), '299999997': (12186380L, 99999997L), '699999999999999993': (11379937003843824L, 99999999999999989L), '799999999999999992': (11374851076515692L, 99999999999999992L), '3997': (152L, 997L), '3996': (152L, 996L), '9999995': (111110, 999990L), '9999994': (111110, 999990L), '9999997': (111110, 999990L), '9999996': (111110, 999990L), '9999991': (111110, 999990L), '9999990': (111110, 999990L), '9999993': (111110, 999990L), '9999992': (111110, 999990L), '9999999': (111111, 999999L), '9999998': (111110, 999990L), '999999999999995': (11111111111110L, 99999999999990L), '999999999999994': (11111111111110L, 99999999999990L), '999999999999997': (11111111111110L, 99999999999990L), '999999999999996': (11111111111110L, 99999999999990L), '999999999999991': (11111111111110L, 99999999999990L), '999999999999990': (11111111111110L, 99999999999990L), '999999999999993': (11111111111110L, 99999999999990L), '999999999999992': (11111111111110L, 99999999999990L), '999999999999999': (11111111111111L, 99999999999999L), '999999999999998': (11111111111110L, 99999999999990L), '79999999993': (1173319226L, 9999999993L), '79999999992': (1173319226L, 9999999992L), '298': (16L, 98L), '297': (16L, 97L), '99999': (1111, 9999L), '99998': (1110, 9990L), '595': (16L, 95L), '594': (16L, 94L), '99991': (1110, 9990L), '99990': (1110, 9990L), '99993': (1110, 9990L), '99992': (1110, 9990L), '99995': (1110, 9990L), '99994': (1110, 9990L), '99997': (1110, 9990L), '99996': (1110, 9990L), '799999999993': (11658399705L, 99999999993L), '799999999992': (11658399705L, 99999999992L), '999993': (11110, 99990L), '799999993': (11920380L, 99999993L), '799999992': (11920380L, 99999992L), '899992': (11950L, 99988L), '899993': (11950L, 99989L), '899990': (11950L, 99986L), '899991': (11950L, 99987L), '899996': (11951L, 99996L), '899997': (11951L, 99997L), '899994': (11951L, 99994L), '899995': (11951L, 99995L), '59999999999999995': (1141743745421432L, 9999999999999995L), '899998': (11951L, 99998L), '899999': (11951L, 99995L), '4999995': (128206L, 999995L), '4999996': (128206L, 999996L), '39997': (1412L, 9997L), '39996': (1412L, 9996L), '1999999999999990': (114596681427059L, 999999999999990L), '4999999999999995': (114596681377522L, 999999999999995L), '5999999999999998': (114596681377422L, 999999999999998L), '5999999999999995': (114596681377422L, 999999999999995L), '99999999995': (1111111110L, 9999999990L), '99999999994': (1111111110L, 9999999990L), '99999999997': (1111111110L, 9999999990L), '99999999996': (1111111110L, 9999999990L), '99999999991': (1111111110L, 9999999990L), '99999999990': (1111111110L, 9999999990L), '99999999993': (1111111110L, 9999999990L), '99999999992': (1111111110L, 9999999990L), '99999999999': (1111111111L, 9999999999L), '99999999998': (1111111110L, 9999999990L), '1990': (151L, 990L), '39999999997': (1184533608L, 9999999997L), '39999999996': (1184533608L, 9999999996L), '1999': (152L, 999L), '1998': (152L, 998L), '2999999999998': (116420033353L, 999999999998L), '59999999995': (1184533560L, 9999999995L), '2999999999997': (116420033353L, 999999999997L), '99999999999999': (1111111111111L, 9999999999999L), '99999999999998': (1111111111110L, 9999999999990L), '59999999998': (1184533561L, 9999999998L), '99999999999991': (1111111111110L, 9999999999990L), '99999999999990': (1111111111110L, 9999999999990L), '99999999999993': (1111111111110L, 9999999999990L), '99999999999992': (1111111111110L, 9999999999990L), '99999999999995': (1111111111110L, 9999999999990L), '99999999999994': (1111111111110L, 9999999999990L), '99999999999997': (1111111111110L, 9999999999990L), '99999999999996': (1111111111110L, 9999999999990L), '799999999999993': (11488237895046L, 99999999999993L), '799999999999992': (11488237895046L, 99999999999992L), '5999999999995': (116420032575L, 999999999995L), '5999999998': (119919923L, 999999998L), '5999999995': (119919923L, 999999995L), '699998': (12702L, 99994L), '495': (16L, 95L), '496': (16L, 96L), '699993': (12701L, 99989L), '699996': (12702L, 99992L), '6999993': (124318L, 999989L), '6999996': (124318L, 999992L), '799996': (12335L, 99996L), '6999998': (124318L, 999994L), '799993': (12334L, 99990L), '799992': (12334L, 99989L), '3999999999996': (116420033347L, 999999999996L), '3999999999997': (116420033347L, 999999999997L), '19999999990': (1184533609L, 9999999990L), '5995': (152L, 995L), '5998': (152L, 998L), '8999999999999992': (114041339075461L, 999999999999992L), '8999999999999993': (114041339075462L, 999999999999993L), '8999999999999990': (114041339075461L, 999999999999990L), '8999999999999991': (114041339075461L, 999999999999991L), '8999999999999996': (114041339075462L, 999999999999996L), '8999999999999997': (114041339075462L, 999999999999997L), '8999999999999994': (114041339075462L, 999999999999994L), '8999999999999995': (114041339075462L, 999999999999995L), '29999998': (1245093L, 9999998L), '8999999999999998': (114041339075462L, 999999999999998L), '8999999999999999': (114041339075462L, 999999999999999L), '599999999999998': (11509595783951L, 99999999999998L), '599999999999995': (11509595783951L, 99999999999995L), '397': (16L, 97L), '396': (16L, 96L), '7999996': (121746L, 999996L), '794': (12L, 91L), '793': (12L, 93L), '7999992': (121745L, 999989L), '790': (11L, 84L), '799': (12L, 93L), '798': (12L, 92L), '2999997': (128206L, 999997L), '4999999996': (119919923L, 999999996L), '2999998': (128206L, 999998L), '199999999990': (11731861572L, 99999999990L), '199999999999': (11731861573L, 99999999999L), '199999999998': (11731861573L, 99999999998L), '79999999999999993': (1140782100326788L, 9999999999999993L), '79999999999999992': (1140782100326788L, 9999999999999992L), '599999998': (12186377L, 99999998L), '599999995': (12186377L, 99999995L), '499999999996': (11731861376L, 99999999996L), '499999999995': (11731861376L, 99999999995L), '19999999999': (1184533610L, 9999999999L), '19999999998': (1184533610L, 9999999998L), '49996': (1412L, 9996L), '199999999999999': (11509595796377L, 99999999999999L), '199999999999998': (11509595796377L, 99999999999998L), '199': (16L, 99L), '199999999999990': (11509595796376L, 99999999999990L), '198': (16L, 98L), '399999999999999996': (11381347508922436L, 99999999999999996L), '19999999999990': (1156936611334L, 9999999999990L), '598': (16L, 98L), '19999999999999': (1156936611335L, 9999999999999L), '19999999999998': (1156936611335L, 9999999999998L), '39999997': (1245093L, 9999997L), '599999999995': (11731861376L, 99999999995L), '599995': (13350L, 99995L), '599999999998': (11731861377L, 99999999998L), '190': (15L, 90L), '99999999999999991': (1111111111111110L, 9999999999999990L), '99999999999999990': (1111111111111110L, 9999999999999990L), '99999999999999993': (1111111111111110L, 9999999999999990L), '99999999999999992': (1111111111111110L, 9999999999999990L), '99999999999999995': (1111111111111110L, 9999999999999990L), '99999999999999994': (1111111111111110L, 9999999999999990L), '99999999999999997': (1111111111111110L, 9999999999999990L), '99999999999999996': (1111111111111110L, 9999999999999990L), '99999999999999998': (1111111111111110L, 9999999999999990L), '899999999998': (11557724122L, 99999999998L), '89999992': (1179181L, 9999992L), '89999993': (1179181L, 9999993L), '89999990': (1179180L, 9999986L), '89999991': (1179180L, 9999987L), '89999996': (1179181L, 9999996L), '89999997': (1179181L, 9999993L), '89999994': (1179181L, 9999994L), '89999995': (1179181L, 9999995L), '89999998': (1179181L, 9999994L), '89999999': (1179181L, 9999995L), '899999999999': (11557724122L, 99999999999L), '999999991': (11111110, 99999990L), '999999990': (11111110, 99999990L), '999999993': (11111110, 99999990L), '999999992': (11111110, 99999990L), '999999995': (11111110, 99999990L), '999999994': (11111110, 99999990L), '999999997': (11111110, 99999990L), '999999996': (11111110, 99999990L), '999999999': (11111111, 99999999L), '999999998': (11111110, 99999990L), '599998': (13350L, 99998L), '1999999990': (119919935L, 999999990L), '69999999999999998': (1141508661373664L, 9999999999999994L), '1999999999': (119919936L, 999999999L), '1999999998': (119919935L, 999999998L), '99999996': (1111110, 9999990L), '69999999999999993': (1141508661373664L, 9999999999999989L), '499999995': (12186377L, 99999995L), '399999997': (12186380L, 99999997L), '399999996': (12186380L, 99999996L), '5999999999998': (116420032576L, 999999999998L), '79996': (1252L, 9996L), '79993': (1251L, 9990L), '79992': (1251L, 9989L), '8999990': (118673L, 999986L), '8999991': (118673L, 999987L), '8999992': (118673L, 999988L), '8999993': (118674L, 999993L), '8999994': (118674L, 999994L), '8999995': (118674L, 999995L), '8999996': (118674L, 999996L), '8999997': (118674L, 999997L), '899999999992': (11557724121L, 99999999992L), '899999999993': (11557724121L, 99999999993L), '899999999990': (11557724121L, 99999999990L), '899999999991': (11557724121L, 99999999991L), '899999999996': (11557724121L, 99999999996L), '899999999997': (11557724122L, 99999999997L), '899999999994': (11557724121L, 99999999994L), '899999999995': (11557724121L, 99999999995L), '79999993': (1203760L, 9999993L), '79999992': (1203760L, 9999992L), '79999996': (1203760L, 9999996L), '89999999999999990': (1137483162790268L, 9999999999999990L), '89999999999999991': (1137483162790268L, 9999999999999991L), '89999999999999992': (1137483162790269L, 9999999999999992L), '89999999999999993': (1137483162790269L, 9999999999999993L), '89999999999999994': (1137483162790269L, 9999999999999994L), '89999999999999996': (1137483162790269L, 9999999999999996L), '89999999999999997': (1137483162790269L, 9999999999999997L), '89999999999999998': (1137483162790269L, 9999999999999998L), '89999999999999999': (1137483162790269L, 9999999999999999L), '693': (13L, 93L), '690': (13L, 90L), '696': (13L, 92L), '694': (13L, 90L), '698': (13L, 94L), '699': (14L, 99L), '7999999999999993': (114453706267526L, 999999999999993L), '7999999999999992': (114453706267525L, 999999999999992L), '6999999999999993': (114557500702794L, 999999999999989L), '995': (10, 90L), '994': (10, 90L), '997': (10, 90L), '996': (10, 90L), '991': (10, 90L), '990': (10, 90L), '993': (10, 90L), '992': (10, 90L), '999': (11, 99L), '998': (10, 90L), '19999999999999998': (1141743745619858L, 9999999999999998L), '19999999999999990': (1141743745619857L, 9999999999999990L), '299998': (13350L, 99998L), '49995': (1412L, 9995L), '59999999999999998': (1141743745421432L, 9999999999999998L), '4999999995': (119919923L, 999999995L), '699999999999993': (11503065671512L, 99999999999989L), '299999999999999997': (11381347508923894L, 99999999999999997L), '4999999999999996': (114596681377522L, 999999999999996L), '19990': (1411L, 9990L), '699999999999998': (11503065671513L, 99999999999994L), '1999990': (128205L, 999990L), '299997': (13350L, 99997L), '3999999997': (119919935L, 999999997L), '19999990': (1245092L, 9999990L), '19999999': (1245093L, 9999999L), '19999998': (1245093L, 9999998L), '39999999999997': (1156936611309L, 9999999999997L), '39999999999996': (1156936611309L, 9999999999996L), '299999998': (12186380L, 99999998L), '9999999999': (111111111, 999999999L), '9999999998': (111111110, 999999990L), '9999999991': (111111110, 999999990L), '9999999990': (111111110, 999999990L), '9999999993': (111111110, 999999990L), '9999999992': (111111110, 999999990L), '999995': (11110, 99990L), '9999999994': (111111110, 999999990L), '9999999997': (111111110, 999999990L), '9999999996': (111111110, 999999990L), '899999990': (11723747L, 99999990L), '899999991': (11723748L, 99999991L), '899999992': (11723748L, 99999992L), '6999999993': (119080145L, 999999989L), '899999994': (11723748L, 99999994L), '899999995': (11723748L, 99999995L), '899999996': (11723748L, 99999996L), '899999997': (11723748L, 99999997L), '899999998': (11723748L, 99999998L), '899999999': (11723748L, 99999999L), '69996': (1304L, 9992L), '69993': (1303L, 9989L), '59995': (1412L, 9995L), '49999999995': (1184533560L, 9999999995L), '49999999996': (1184533560L, 9999999996L), '69998': (1304L, 9994L), '1999999999990': (116420033356L, 999999999990L), '1999999999999': (116420033357L, 999999999999L), '1999999999998': (116420033357L, 999999999998L), '3999997': (128206L, 999997L), '3999996': (128206L, 999996L), '7993': (126L, 990L), '7992': (126L, 989L), '7996': (127L, 996L), '7994': (126L, 988L), '7998': (127L, 998L), '399997': (13350L, 99997L), '399996': (13350L, 99996L), '69999998': (1221765L, 9999994L), '69999993': (1221764L, 9999989L), '899999999999990': (11436691996038L, 99999999999990L), '899999999999991': (11436691996038L, 99999999999991L), '899999999999992': (11436691996038L, 99999999999992L), '899999999999993': (11436691996038L, 99999999999993L), '899999999999994': (11436691996039L, 99999999999994L), '899999999999995': (11436691996039L, 99999999999995L), '899999999999996': (11436691996039L, 99999999999996L), '899999999999997': (11436691996039L, 99999999999997L), '899999999999998': (11436691996039L, 99999999999998L), '899999999999999': (11436691996039L, 99999999999999L), '499999996': (12186377L, 99999996L), '999999': (11111, 99999L), '599999999999999998': (11381347508130432L, 99999999999999998L), '999998': (11110, 99990L), '499999999999999995': (11381347508132932L, 99999999999999995L), '399999999999997': (11509595796307L, 99999999999997L), '399999999999996': (11509595796307L, 99999999999996L), '8999999999990': (115130628208L, 999999999990L), '8999999999991': (115130628208L, 999999999991L), '8999999999992': (115130628208L, 999999999992L), '8999999999993': (115130628208L, 999999999993L), '8999999999994': (115130628208L, 999999999994L), '8999999999995': (115130628208L, 999999999995L), '8999999999996': (115130628209L, 999999999996L), '8999999999997': (115130628209L, 999999999997L), '8999999999998': (115130628209L, 999999999998L), '8999999999999': (115130628209L, 999999999999L), '890': (11L, 90L), '891': (11L, 89L), '892': (11L, 90L), '893': (11L, 89L), '894': (11L, 90L), '895': (11L, 89L), '896': (11L, 90L), '897': (12L, 97L), '898': (12L, 98L), '899': (12L, 99L), '999991': (11110, 99990L), '699999998': (12046414L, 99999994L), '999990': (11110, 99990L), '699999993': (12046414L, 99999989L), '99999999': (1111111, 9999999L), '99999998': (1111110, 9999990L), '999992': (11110, 99990L), '99999990': (1111110, 9999990L), '99999991': (1111110, 9999990L), '9999999995': (111111110, 999999990L), '99999993': (1111110, 9999990L), '99999992': (1111110, 9999990L), '99999995': (1111110, 9999990L), '99999994': (1111110, 9999990L), '99999997': (1111110, 9999990L), '999994': (11110, 99990L), '49999996': (1245092L, 9999996L), '49999995': (1245092L, 9999995L), '999997': (11110, 99990L), '999996': (11110, 99990L), '699999999998': (11701629374L, 99999999994L), '3999999996': (119919935L, 999999996L), '699999999993': (11701629373L, 99999999989L), '59999999999995': (1156936608221L, 9999999999995L), '69999999993': (1179494892L, 9999999989L), '1999999': (128206L, 999999L), '1999998': (128206L, 999998L), '69999999998': (1179494893L, 9999999994L), '59999999999998': (1156936608221L, 9999999999998L), '89999999999992': (1147286764991L, 9999999999992L), '89999999999993': (1147286764991L, 9999999999993L), '89999999999990': (1147286764991L, 9999999999990L), '89999999999991': (1147286764991L, 9999999999991L), '89999999999996': (1147286764992L, 9999999999996L), '89999999999997': (1147286764992L, 9999999999997L), '89999999999994': (1147286764991L, 9999999999994L), '89999999999995': (1147286764992L, 9999999999995L), '89999999999998': (1147286764992L, 9999999999998L), '89999999999999': (1147286764992L, 9999999999999L), '299999999999997': (11509595796361L, 99999999999997L), '1999999999999999': (114596681427060L, 999999999999999L), '1999999999999998': (114596681427060L, 999999999999998L), '899999999999999991': (11348459576223540L, 99999999999999991L), '299999999999998': (11509595796361L, 99999999999998L), '2998': (152L, 998L), '6998': (134L, 994L), '6999': (134L, 995L), '59999995': (1245092L, 9999995L), '6996': (134L, 992L), '6990': (133L, 986L), '6993': (133L, 989L), '29998': (1412L, 9998L), '399999999997': (11731861569L, 99999999997L), '399999999996': (11731861568L, 99999999996L), '29997': (1412L, 9997L), '3999999999999997': (114596681426866L, 999999999999997L), '3999999999999996': (114596681426866L, 999999999999996L), '6999999999993': (116238640562L, 999999999989L), '29999997': (1245093L, 9999997L), '6999999999998': (116238640563L, 999999999994L), '2997': (152L, 997L), '89999999990': (1160734778L, 9999999990L), '89999999991': (1160734778L, 9999999991L), '89999999992': (1160734778L, 9999999992L), '89999999993': (1160734778L, 9999999993L), '89999999994': (1160734778L, 9999999994L), '89999999995': (1160734778L, 9999999995L), '89999999996': (1160734778L, 9999999996L), '89999999997': (1160734778L, 9999999997L), '89999999998': (1160734779L, 9999999998L), '89999999999': (1160734779L, 9999999999L), '499999999999995': (11509595783971L, 99999999999995L), '9999': (111, 999L), '9998': (110, 990L), '9991': (110, 990L), '9990': (110, 990L), '9993': (110, 990L), '9992': (110, 990L), '9995': (110, 990L), '9994': (110, 990L), '9997': (110, 990L), '9996': (110, 990L), '299999999998': (11731861571L, 99999999998L), '199999999': (12186380L, 99999999L), '199999998': (12186380L, 99999998L), '299999999997': (11731861571L, 99999999997L), '2999999997': (119919935L, 999999997L), '2999999999999997': (114596681427028L, 999999999999997L), '2999999999999998': (114596681427028L, 999999999999998L), '2999999998': (119919935L, 999999998L), '9999999999999': (111111111111L, 999999999999L), '9999999999998': (111111111110L, 999999999990L), '6999999999999998': (114557500702794L, 999999999999994L), '9999999999991': (111111111110L, 999999999990L), '9999999999990': (111111111110L, 999999999990L), '9999999999993': (111111111110L, 999999999990L), '9999999999992': (111111111110L, 999999999990L), '9999999999995': (111111111110L, 999999999990L), '9999999999994': (111111111110L, 999999999990L), '9999999999997': (111111111110L, 999999999990L), '9999999999996': (111111111110L, 999999999990L), '899999993': (11723748L, 99999993L), '199999990': (12186379L, 99999990L), '39999999999999997': (1141743745619308L, 9999999999999997L), '39999999999999996': (1141743745619308L, 9999999999999996L), '29999999999998': (1156936611327L, 9999999999998L), '6999999998': (119080145L, 999999994L), '49999999999999995': (1141743745421932L, 9999999999999995L), '29999999997': (1184533608L, 9999999997L), '49999999999999996': (1141743745421932L, 9999999999999996L), '199999999999999998': (11381347508924022L, 99999999999999998L), '39999996': (1245092L, 9999996L), '59998': (1412L, 9998L), '89990': (1203L, 9990L), '89991': (1203L, 9987L), '89992': (1203L, 9988L), '89993': (1203L, 9989L), '89994': (1203L, 9990L), '89995': (1204L, 9995L), '89996': (1204L, 9996L), '89997': (1204L, 9997L), '89998': (1204L, 9998L), '89999': (1204L, 9999L), '7999999999993': (115936032880L, 999999999993L), '7999999999992': (115936032880L, 999999999992L), '8999999998': (116624851L, 999999998L), '8999999999': (116624852L, 999999999L), '8999999992': (116624851L, 999999992L), '8999999993': (116624851L, 999999993L), '8999999990': (116624851L, 999999990L), '8999999991': (116624851L, 999999991L), '8999999996': (116624851L, 999999996L), '8999999997': (116624851L, 999999997L), '8999999994': (116624851L, 999999994L), '8999999995': (116624851L, 999999995L), '8999998': (118674L, 999994L), '8999999': (118674L, 999995L), '19999': (1412L, 9999L), '19998': (1412L, 9998L), '199990': (13349L, 99990L), '49999999999995': (1156936608225L, 9999999999995L), '199999': (13350L, 99999L), '199998': (13350L, 99998L), '69999999999998': (1155848256148L, 9999999999994L), '69999999999993': (1155848256147L, 9999999999989L), '4996': (152L, 996L), '4999999999995': (116420032575L, 999999999995L), '499996': (13350L, 99996L), '79999999999993': (1153730002367L, 9999999999993L), '499995': (13350L, 99995L), '79999999999992': (1153730002367L, 9999999999992L), '9999999999999999': (111111111111111L, 999999999999999L), '9999999999999998': (111111111111110L, 999999999999990L), '499999999999996': (11509595783971L, 99999999999996L), '29999999999997': (1156936611327L, 9999999999997L), '7999999993': (118197907L, 999999993L), '7999999992': (118197907L, 999999992L), '796': (12L, 93L), '9999999999999991': (111111111111110L, 999999999999990L), '9999999999999990': (111111111111110L, 999999999999990L), '9999999999999993': (111111111111110L, 999999999999990L), '9999999999999992': (111111111111110L, 999999999999990L), '9999999999999995': (111111111111110L, 999999999999990L), '9999999999999994': (111111111111110L, 999999999999990L), '9999999999999997': (111111111111110L, 999999999999990L), '9999999999999996': (111111111111110L, 999999999999990L), '49999999999996': (1156936608225L, 9999999999996L), '29999999998': (1184533609L, 9999999998L), '7999993': (121746L, 999993L), '792': (12L, 92L), '8998': (121L, 998L), '8999': (121L, 997L), '59999998': (1245093L, 9999998L), '8992': (120L, 988L), '8993': (120L, 989L), '8990': (120L, 988L), '8991': (120L, 989L), '8996': (121L, 996L), '8997': (121L, 997L), '8994': (120L, 988L), '8995': (120L, 989L), '999999999999': (11111111111L, 99999999999L), '999999999998': (11111111110L, 99999999990L), '4999999999996': (116420032576L, 999999999996L), '4995': (152L, 995L), '999999999991': (11111111110L, 99999999990L), '999999999990': (11111111110L, 99999999990L), '999999999993': (11111111110L, 99999999990L), '999999999992': (11111111110L, 99999999990L), '999999999995': (11111111110L, 99999999990L), '999999999994': (11111111110L, 99999999990L), '999999999997': (11111111110L, 99999999990L), '999999999996': (11111111110L, 99999999990L)}

def calc(x):
	ans = 0
	while x > 0:
		t = "0" + str(x)
		p = len(t)-2
		while(str(t)[p] == '9'):
			p -= 1
		head = str(t)[:p+1]
		tail = str(t)[p+1:]
		important = max(head) + tail

		if not important in quickTable:
			WaitingList[(head, len(tail))] = (ans, x, max(head) + tail)
		if x == 123:
			print (head, len(tail))

		t = "0" + str(x)
		p = len(t)-2
		while p > 0:
			head = str(t)[:p+1]
			tail = str(t)[p+1:]
			if x == 123:
				print "->", (head, len(tail))
			if (head, len(tail)) in WaitingList:
				lastAns, lastX, imp = WaitingList[(head, len(tail))]
				if x != lastX:
					quickTable[imp] = (ans - lastAns, lastX - x)
			p -= 1


		if important in quickTable:
			usedSteps, to = quickTable[important]
			ans += usedSteps
			x -= to
		else:
			ans += 1
			x -= int(max(str(x)))
	return ans

x = eval(raw_input())
print calc(x)
