Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.

You have to find the minimum number of digits in which these two numbers can differ.


-----Input-----

The first line contains integer k (1 ≤ k ≤ 10^9).

The second line contains integer n (1 ≤ n < 10^100000).

There are no leading zeros in n. It's guaranteed that this situation is possible.


-----Output-----

Print the minimum number of digits in which the initial number and n can differ.


-----Examples-----
Input
3
11

Output
1

Input
3
99

Output
0



-----Note-----

In the first example, the initial number could be 12.

In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.

Difficulty: EASY
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
a = input()
a_integer = int(a)
b = input()
b_len = len(b)
b_sum = 0
lis = []
c = 0
for i in range(len(b)):
	b_sum = b_sum + int(b[i])
for i in range(len(b)):
	lis.append(int(b[i]))
lis.sort()
if b_sum >= a_integer:
	print(c)
else:
	for i in range(len(b)):
		b_sum = b_sum + 9 - lis[i]
		c = c + 1
		if b_sum >= a_integer:
			print(c)
			break


k = int(input())
n = int(input())
l = list(str(n))
l = [int(i) for i in l]
l.sort()
ans = 0
su = sum(l)
if su >= k:
	print(0)
else:
	for i in l:
		if su + abs(i - 9) >= k:
			print(ans + 1)
			break
		else:
			ans += 1
			su = su + abs(i - 9)


K = int(input())
n = list(map(int, str(int(input()))))
n.sort()
cur = sum(n)
ans = 0
ind = 0
while cur < K:
	cur += 9 - n[ind]
	ind += 1
	ans += 1
print(ans)


def r():
	return list(map(int, input().split()))
k = int(input())
s = sorted(map(int, input()))
(ck, i) = (sum(s), 0)
while ck < k:
	ck += 9 - s[i]
	i += 1
print(i)


import sys
import math
import itertools
import collections

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ''.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
k = ii()
n = sorted(list(map(int, input())))
nsum = sum(n)
ans = 0
while nsum < k:
	nsum += 9 - n[ans]
	ans += 1
print(ans)


(k, n, v) = (int(input()), input(), 0)
s = k - sum((int(d) for d in n))
for d in map(int, sorted(n)):
	if s <= 0:
		break
	(s, v) = (s - (9 - d), v + 1)
print(v)


k = int(input())
n = list(map(int, input()))
a = [0] * 10
s = 0
for i in n:
	a[i] += 1
	s += i
ans = 0
ind = 0
while s < k:
	while a[ind] == 0:
		ind += 1
	a[ind] -= 1
	s -= ind
	s += 9
	ans += 1
print(ans)


from math import ceil
k = int(input())
n = input()
sm = 0
cnt = 0
l = [0] * 10
for i in n:
	l[int(i)] += 1
for i in range(10):
	sm += l[i] * i
if sm >= k:
	print(0)
	exit()
for i in range(10):
	for j in range(l[i]):
		if sm < k:
			cnt += 1
			sm += 9 - i
print(cnt)


def digisum(num):
	count = 0
	while num != '':
		count += int(num[-1])
		num = num[:len(num) - 1]
	return count
k = int(input())
n = input()
total = digisum(n)
if total >= k:
	print(0)
else:
	arr = list(map(str, n))
	arr.sort()
	arr = ''.join((str(x) for x in arr))
	diff = k - total
	ind = 0
	count = 0
	while diff > 0:
		cur = 9 - int(arr[ind])
		diff -= cur
		ind += 1
		count += 1
	print(count)


k = int(input())
digits = list(map(int, list(input())))
digits.sort()
ans = 0
i = 0
sumD = sum(digits)
while sumD < k:
	ans += 1
	sumD += 9 - digits[i]
	i += 1
print(ans)


read = lambda : map(int, input().split())
k = int(input())
n = sorted(input())
cur = sum((int(i) for i in n))
cnt = 0
for i in range(len(n)):
	if cur >= k:
		break
	add = int('9') - int(n[i])
	cur += add
	cnt += 1
print(cnt)


k = int(input())
n = input()
a = list(map(int, n))
l = sum(a)
changed = 0
if l < k:
	for num in sorted(a):
		l = l + 9 - num
		changed = changed + 1
		if l >= k:
			break
print(changed)


k = int(input())
n = input()
_sum = 0
data = []
for x in n:
	data.append(int(x))
	_sum = _sum + int(x)
if _sum >= k:
	print('0')
else:
	_sum = k - _sum
	data.sort()
	_ans = 0
	for x in data:
		_ans = _ans + 1
		_sum = _sum - 9 + x
		if _sum <= 0:
			break
	print(_ans)


import sys
k = int(input())
n = input()
cambios = 0
total = 0
for num in n:
	total = total + int(num)
if total > k:
	print('0')
	sys.exit()
elif total < k:
	dif = k - total
	n = [int(i) for i in str(n)]
	n.sort()
	for x in range(0, len(n)):
		cambios = cambios + 1
		dif = dif - (9 - n[x])
		if dif <= 0:
			print(cambios)
			sys.exit()
print(cambios)


def handle(a, k):
	a.sort()
	cnt = 0
	tmp = sum(a)
	if tmp >= k:
		return 0
	for item in a:
		if tmp >= k:
			return cnt
		else:
			cnt += 1
			tmp = tmp - item + 9
	return cnt
k = int(input())
n = input()
a = list(map(int, n))
ans = handle(a, k)
print(ans)


a = int(input())
b = input()
my = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
sum = ans = 0
for i in b:
	sum += int(i)
	my[int(i)] += 1
for i in range(10):
	if sum >= a:
		print(ans)
		break
	else:
		for j in range(my[i]):
			sum += 9 - i
			ans += 1
			if sum >= a:
				break


k = int(input())
n = [int(i) for i in input()]
s = sum(n)
n.sort()
o = 0
for i in n:
	if s >= k:
		break
	else:
		s += 9 - i
		o += 1
print(o)


t = int(input())
s = list(input())
s.sort()
l = 0
for i in range(len(s)):
	l += int(s[i])
if l < t:
	c = t - l
	i = 0
	while c > 0 & i < len(s):
		c -= 9 - int(s[i])
		i += 1
	print(i)
else:
	print('0')


k = int(input())
n = input()
l = n
count = 0
for i in n:
	count += int(i)
ctr = 0
if count >= k:
	print('0')
else:
	n = sorted(n)
	i = 0
	while count < k:
		s = 9 - int(n[i])
		ctr += 1
		count += s
		if count >= k:
			print(ctr)
		i += 1


k = int(input())
n = input()
(lst, summa) = ([], 0)
for (i, x) in enumerate(n):
	x = int(x)
	lst.append(x)
	summa += x
i = -1
if summa < k:
	lst.sort()
	for (i, x) in enumerate(lst):
		summa += 9 - x
		if summa >= k:
			break
print(i + 1)


I = lambda : map(int, input().split())
(k,) = I()
(num,) = I()
numlist = list(map(int, list(str(num))))
numlist = sorted(numlist)
ln = len(numlist)
diff = k - sum(numlist)
ans = 0
for i in range(0, ln):
	if diff <= 0:
		break
	ans += 1
	diff -= 9 - numlist[i]
print(ans)


k = input()
n = input()
s = sum(map(int, n))
ns = list(map(int, n))
ns.sort()
df = int(k) - s
if df <= 0:
	print(0)
else:
	out = 0
	for i in ns:
		df -= 9 - i
		out += 1
		if df <= 0:
			break
	print(out)


k = int(input())
n = input()
N = sorted(n)
for i in N:
	k -= int(i)
ans = 0
for i in N:
	if k <= 0:
		break
	k += int(i) - 9
	ans += 1
print(ans)


s = int(input())
l = list(input())
c = 0
for i in l:
	c += int(i)
if c >= s:
	print(0)
else:
	s = s - c
	c = 0
	l.sort()
	for i in l:
		s -= 9 - int(i)
		c += 1
		if s <= 0:
			print(c)
			break


import math

def main():
	k = int(input())
	n = input()
	sum = 0
	b = list(n)
	b.sort()
	for char in n:
		sum += int(char)
	if sum >= k:
		print(0)
	else:
		x = abs(sum - k)
		count = 0
		for elem in b:
			k = 9 - int(elem)
			x = x - k
			count += 1
			if x <= 0:
				break
		print(count)
main()


def number_board(k, n):
	arr = [0] * 10
	accum = 0
	r = 0
	for i in n:
		digit = int(i)
		if accum > k:
			return r
		else:
			arr[digit] += 1
			accum += digit
	for i in range(0, 10):
		for j in range(0, arr[i]):
			if accum >= k:
				return r
			accum += 9 - i
			r += 1
	return r
k = int(input())
n = input()
print(number_board(k, n))


from math import *
k = int(input())
s = input()
k2 = min(k, sum(map(int, s)))
l = list(map(int, sorted(s)))
i = 0
while k2 < k:
	k2 += 9 - l[i]
	i += 1
print(i)


k = int(input())
n = sorted([int(i) for i in input()])
s = 0
for i in n:
	s += i
j = 0
ans = 0
if k > s:
	for i in n:
		if s >= k:
			break
		s += 9 - i
		ans += 1
print(ans)


k = int(input())
n = input()
counts = [None] * 10
offset = ord('0')
sum = 0
for i in range(10):
	counts[i] = n.count(chr(i + offset))
	sum += i * counts[i]
if sum < k:
	count = 0
	for i in range(9):
		for j in range(counts[i]):
			count += 1
			sum += 10 + ~i
			if sum >= k:
				print(count)
				exit()
else:
	print(0)


def main():
	k = int(input())
	n = input()
	print(solver(n, k))

def solver(n, k):
	digits = [0] * 9
	for c in n:
		x = int(c)
		if x != 9:
			digits[x] += 1
		k -= x
	changed = 0
	for i in range(len(digits)):
		if k <= 0:
			return changed
		needed = (k + 8 - i) // (9 - i)
		if digits[i] >= needed:
			return changed + needed
		else:
			changed += digits[i]
			k -= digits[i] * (9 - i)
main()


k = int(input())
n = input()
a = []
for i in range(len(n)):
	a.append(int(n[i]))
sum = 0
for i in range(len(a)):
	sum += a[i]
l = sum - k
l1 = 0
m = 0
if l >= 0:
	print(0)
else:
	a.sort()
	l = abs(l)
	for i in range(len(a)):
		l1 += 9 - a[i]
		m += 1
		if l1 >= l:
			print(m)
			break


import sys
(n, k) = sys.stdin.read().split()
sum_k = 0
for x in str(k):
	sum_k = sum_k + ord(x) - ord('0')
if sum_k >= int(n):
	print(0)
else:
	l = sorted(str(k))
	cnt = 0
	for x in l:
		if sum_k - (ord(x) - ord('0')) + 9 >= int(n):
			cnt += 1
			break
		else:
			sum_k = sum_k - (ord(x) - ord('0')) + 9
			cnt += 1
	print(cnt)


k = int(input())
numstring = input()
num = []
sumN = 0
for chac in numstring:
	sumN += int(chac)
	num += [int(chac)]
if sumN >= k:
	print('0')
else:
	num.sort()
	diffK = k - sumN
	diffSol = 0
	for n in num:
		maxn = 9 - n
		if maxn < diffK:
			diffK -= maxn
			diffSol += 1
		else:
			diffSol += 1
			break
	print(diffSol)


k = int(input())
s = input()
sum = 0
counter = 0
for i in range(0, s.__len__()):
	sum += int(s[i])
	if sum >= k:
		print('0')
		exit()
s = ''.join(sorted(s))
for i in range(0, s.__len__()):
	sum += 9 - int(s[i])
	counter += 1
	if sum >= k:
		print(counter)
		exit()


k = int(input())
l = sorted([int(i) for i in input()])
(ans, s) = (0, sum(l))
i = 0
while s < k:
	s += 9 - l[i]
	ans += 1
	i += 1
print(ans)


s = int(input())
num = str(input())
l = []
for i in num:
	l.append(int(i))
sss = sum(l)
c = s - sss
if c <= 0:
	print(0)
else:
	l.sort()
	i = 0
	while c > 0:
		c -= 9 - l[i]
		i += 1
	print(i)


k = int(input())
n = input()
digits = []
for i in n:
	digits.append(ord(i) - ord('0'))
digits.sort()
cur = sum(digits)
ans = 0
for d in digits:
	if cur < k:
		cur += 9 - d
		ans += 1
print(ans)


k = int(input())
n = input()
s_n = 0
for i in n:
	s_n += int(i)
if s_n >= k:
	print(0)
else:
	n = sorted(n)
	change = 0
	amader_lagbe = k - s_n
	for (i, char) in enumerate(n):
		now_sum = 9 - int(char)
		amader_lagbe -= now_sum
		if amader_lagbe <= 0:
			print(change + 1)
			exit()
		change += 1


k = int(input())
n = input()
dig = []
for x in n:
	dig.append(int(x))
dig.sort()
s = sum(dig)
count = 0
l = 0
while s < k:
	count += 1
	s += 9 - dig[l]
	l += 1
print(count)


def digit_array(s):
	return map(int, list(s))

def solve(arr, s):
	count = 0
	for i in arr:
		able_to_add = 9 - i
		s -= able_to_add
		count += 1
		if s <= 0:
			break
	return count
k = int(input())
digits = sorted(digit_array(input()))
actual_sum = sum(digits)
if actual_sum >= k:
	print('0')
else:
	res = solve(digits, k - actual_sum)
	print(res)


k = int(input())
data = sorted(list(map(int, list(input()))))
currentSum = sum(data)
ans = 0
ind = 0
while currentSum < k:
	currentSum += 9 - data[ind]
	ind += 1
	ans += 1
print(ans)


k = int(input())
s = input()
sum = 0
for a in s:
	a = int(a)
	sum += a
if sum >= k:
	print(0)
else:
	q = 0
	n = 0
	new1 = list(s)
	new1.sort()
	while n < len(s):
		sum -= int(new1[0])
		sum += 9
		new1.remove(new1[0])
		q += 1
		n += 1
		if sum >= k:
			print(q)
			break
	else:
		print(0)


k = int(input())
n = [int(x) for x in list(input())]
total = 0
n.sort()
for d in n:
	total += d
if total >= k:
	print(0)
else:
	ans = 0
	left = k - total
	while left > 0:
		if ans == len(n):
			break
		left -= 9 - n[ans]
		ans += 1
	print(ans)


import sys
k = int(input())
n = input()
l = [int(i) for i in n]
l = sorted(l)
sm = 0
cnt = 0
if sum(l) >= k:
	print(0)
	sys.exit()
else:
	sm = sum(l)
	for i in range(len(l)):
		sm += 9 - l[i]
		cnt += 1
		if sm >= k:
			break
print(cnt)


def f(k, n):
	cs = sum(n)
	i = len(n) - 1
	n = sorted(n)
	cnt = 0
	for i in n:
		if cs < k:
			cs -= i
			cs += 9
			cnt += 1
		else:
			break
	return cnt
k = int(input())
n = list(input())
n = list(map(int, n))
print(f(k, n))


def main():
	s1 = int(input())
	raw = input()
	data = [0] * 10
	for val in raw:
		data[int(val)] += 1
	s2 = 0
	for ind in range(1, 10):
		s2 += data[ind] * ind
	changes = 0
	q = 0
	while s1 > s2:
		if data[q] > 0:
			data[q] -= 1
			s2 += 9 - q
			changes += 1
		else:
			q += 1
	print(changes)
main()


def find_min_char(k: int, n: str) -> int:
	chars = list(n)
	int_list = list(map(int, chars))
	true_k = sum(int_list)
	int_list.sort()
	need_inc = k - true_k
	min_char = 0
	for i in int_list:
		if need_inc <= 0:
			return min_char
		min_char += 1
		need_inc -= 9 - i
	return min_char
k = int(input())
n = str(input())
result = find_min_char(k, n)
print(result)


k = int(input())
l = sorted(map(int, input()))
i = 0
su = sum(l)
while su < k:
	su += 9 - l[i]
	i += 1
print(i)


k = int(input())
n = list(input())
sum = 0
for i in range(len(n)):
	n[i] = int(n[i])
	sum += n[i]
mind = 0
n.sort()
while True:
	if sum >= k:
		break
	sum += 9 - n[mind]
	mind += 1
print(mind)


k = int(input())
n = list(map(int, list(input().strip())))
n.sort()
s = sum(n)
c = 0
i = 0
while s < k:
	s += 9 - n[i]
	i += 1
	c += 1
print(c)


(k, n) = (int(input()), input())
n = list(map(int, sorted(list(n))))
s = sum(n) - len(n) * int('0')
if s >= k:
	print('0')
else:
	for i in range(len(n)):
		s += 9 - (n[i] - int('0'))
		if s >= k:
			print(i + 1)
			break


k = int(input())
a = list(input())
a.sort()
sumDigit = 0
for i in a:
	sumDigit += ord(i) - 48
index = 0
while sumDigit < k:
	sumDigit -= ord(a[index]) - 48
	sumDigit += 9
	index += 1
print(index)


k = int(input())
n = list(input())
s = 0
for i in n:
	s += int(i)
if s >= k:
	print(0)
else:
	d = k - s
	n.sort()
	c = 0
	for i in n:
		c += 1
		d = d - min(d, 9 - int(i))
		if d == 0:
			break
	print(c)


lectura = lambda : map(int, input())
k = list(lectura())
m = list(lectura())
M = sum(m)
m.sort()
a = 0
K = int(''.join(map(str, k)))
while M < K:
	M += 9 - m[a]
	a += 1
print(a)


k = int(input())
n = input()
n = list(n)
n.sort()
nint = [int(i) for i in n]
soma = sum(nint)
count = 0
for a in nint:
	if soma >= k:
		break
	else:
		soma += 9 - a
		count += 1
print(count)


from collections import Counter

def sum_digits(n):
	count = Counter(n)
	res = 0
	for (k, v) in count.items():
		res += int(k) * v
	return res
k = int(input())
num = input()

def find(k, num):
	count = 0
	temp = num
	sum = sum_digits(num)
	if k == 1 and k - sum <= 0:
		return 0
	for i in range(10):
		for j in range(len(temp)):
			if k - sum <= 0:
				return count
			if i == int(temp[j]):
				sum = sum - i + 9
				temp = temp.replace(str(i), '9', 1)
				count += 1
print(find(k, num))


from collections import defaultdict
from math import ceil
k_sum = int(input())
n_sum = 0
n_digits = defaultdict(int)
for c in list(map(int, list(input()))):
	n_sum += c
	n_digits[c] += 1
if n_sum >= k_sum:
	print(0)
else:
	diff_digits = 0
	for i in range(9):
		if i not in n_digits:
			continue
		diff = k_sum - n_sum
		every_digit_adds = 9 - i
		if diff >= every_digit_adds * n_digits[i]:
			n_sum += every_digit_adds * n_digits[i]
			diff_digits += n_digits[i]
			n_digits[i] = 0
		else:
			needed_digits = int(ceil(diff / every_digit_adds))
			n_sum += every_digit_adds * needed_digits
			diff_digits += needed_digits
			n_digits[i] -= needed_digits
			break
	print(diff_digits)


k = int(input())
n = [int(x) for x in input()]
answer = 0
n.sort()
cur = sum(n)
for d in n:
	if cur < k:
		cur += 9 - d
		answer += 1
print(answer)


k = int(input())
n = [int(i) for i in list(input())]
s = sum(n)
if s >= k:
	print(0)
else:
	l = k - s
	p = sorted(n)
	o = 0
	for i in range(len(p)):
		if l > 0:
			l -= 9 - p[i]
			o += 1
	print(o)


k = int(input())
s = input()
c = 0
l = 0
for i in s:
	c += int(i)
if c >= k:
	print(0)
else:
	c = k - c
	q = sorted(list(s))
	for i in range(len(q)):
		p = min(9 - int(q[i]), c)
		c -= p
		l += 1
		if c <= 0:
			break
	print(l)


k = int(input())
n = input().strip()
sum = 0
for i in n:
	sum += int(i)
if sum >= k:
	print(0)
else:
	c = 0
	n = list(n)
	length = len(n)
	for i in range(length):
		n[i] = int(n[i])
	n.sort()
	f = 0
	for i in range(length):
		if sum >= k:
			print(c)
			f = 1
			break
		else:
			sum += 9 - n[i]
			c += 1
	if f == 0:
		print(length)


import os
import sys
from io import BytesIO, IOBase
from functools import reduce
(n, k) = [None] * 2

def getInput() -> None:
	global n, k
	k = int(input())
	n = [int(i) for i in sorted(input())]

def main():
	getInput()
	diff = k - sum(n)
	cnt = 0
	for i in n:
		if diff <= 0:
			break
		if diff + i > 9:
			diff -= 9 - i
		else:
			diff = 0
		cnt += 1
	print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math

def main():
	k = int(input())
	n = str(input())
	arr = [int(i) for i in n]
	arr.sort()
	add = sum(arr)
	cnt = 0
	for i in range(len(arr)):
		if add >= k:
			print(cnt)
			return
		else:
			add += 9 - arr[i]
			cnt += 1
	print(cnt)
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [tuple(map(int, l.split())) for l in sys.stdin]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	k = I()
	a = sorted([int(c) for c in S()])
	k -= sum(a)
	r = 0
	for c in a:
		if k <= 0:
			break
		r += 1
		k -= 9 - c
	return r
print(main())


k = int(input())
n = int(input())
digits = [int(z) for z in str(n)]
digits.sort()
if sum(digits) < k:
	rc = sum(digits)
	p1 = 0
	while rc < k:
		rc += 10 - digits[p1] - 1
		p1 += 1
	print(p1)
else:
	print(0)


k = int(input())
list_ = sorted([int(i) for i in input()])
sum_ = sum(list_)
cnt_ = 0
while k > sum_:
	sum_ += 9 - list_[cnt_]
	cnt_ += 1
print(cnt_)


import time
k = int(input())
n = int(input())
initial_time = time.time()
digits_n = list(map(int, str(n)))
counter = 0
digits_n = sorted(digits_n)
suma = sum(digits_n)
if k <= suma:
	print(0)
else:
	i = 0
	while i < digits_n.__len__():
		if digits_n[i] != 9:
			counter += 1
			suma += 9 - digits_n[i]
			i += 1
		if suma >= k:
			break
	print(counter)


k = int(input())
starr = list(input())
n = len(starr)
sum = 0
for i in range(n):
	starr[i] = int(starr[i])
	sum += starr[i]
starr.sort()
ctr = 0
for a in starr:
	if sum >= k:
		break
	sum -= a
	sum += 9
	ctr += 1
print(int(ctr))


k = int(input())
st = input()
n = [int(ch) for ch in st]
n.sort()
for i in range(len(n)):
	k -= n[i]
if k <= 0:
	print(0, end='')
else:
	for i in range(len(n)):
		k -= 9 - n[i]
		if k <= 0:
			break
	print(i + 1, end='')


def sm(a):
	s = 0
	for i in a:
		s += i
	return s
k = int(input())
n = list(map(int, list(input())))
n.sort()
s = sm(n)
c = 0
while s < k:
	s += 9 - n[c]
	c += 1
print(c)


from collections import Counter

def main():
	k = int(input())
	cnt = Counter()
	n = input()
	s = 0
	for e in map(int, n):
		cnt[e] += 1
		s += e
	if s >= k:
		print('0')
		return
	else:
		res = 0
		diff = k - s
		for i in sorted(cnt.keys()):
			for j in range(cnt[i]):
				diff -= 9 - i
				res += 1
				if diff <= 0:
					print(res)
					exit()
	print(-1)
main()


n = int(input(''))
b = input('')
suma = 0
for k in b:
	suma += int(k)
b = sorted(b)
if suma < n:
	cont = 0
	a = n - suma
	while a > 0:
		a -= 9 - int(b[cont])
		cont += 1
	print(cont)
else:
	print(0)


k = int(input())
num = map(int, input())
count = [0 for _ in range(10)]
from math import ceil
s = 0
for n in num:
	s += n
	count[n] += 1
diff = k - s
digits = 0
for i in range(9):
	if diff < 0:
		break
	if diff < count[i] * (9 - i):
		digits += ceil(diff / (9 - i))
		diff -= (9 - i) * ceil(diff / (9 - i))
	else:
		digits += count[i]
		diff -= count[i] * (9 - i)
print(digits)


k = int(input())
n = input()
digits = [0] * 26
sum = 0
for char in n:
	x = ord(char) - ord('0')
	digits[x] += 1
	sum += x
res = 0
for i in range(9):
	if sum < k:
		delta = k - sum
		value = min(delta, (9 - i) * digits[i])
		increase = value // (9 - i)
		if value % (9 - i) != 0:
			increase += 1
		sum += increase * (9 - i)
		res += increase
print(res)


k = int(input())
n = sorted(list(map(int, input())))
if sum(n) >= k:
	print(0)
else:
	s = 0
	k1 = sum(n)
	for p in n:
		s += 1
		k1 += 9 - p
		if k1 >= k:
			print(s)
			break


k = int(input())
s = input()
n = 0
c = [0] * 10
for a in s:
	n += int(a)
	c[int(a)] += 1
if n >= k:
	print(0)
else:
	count = 0
	flag = False
	for i in range(10):
		while c[i]:
			c[i] -= 1
			n += 9 - i
			count += 1
			if n >= k:
				print(count)
				flag = True
				break
		if flag:
			break


k = int(input())
n = input()
lsum = 0
for x in n:
	lsum += int(x)
if lsum >= k:
	print(0)
else:
	a = [int(x) for x in sorted(n)]
	cur = sum(a)
	for (i, x) in enumerate(a, 0):
		a[i] = 9
		cur += 9 - x
		if cur >= k:
			print(i + 1)
			break


k = int(input())
n = [int(i) for i in input()]
cs = 0
for i in n:
	cs += i
n.sort()
v = k - cs
res = 0
for i in n:
	if v <= 0:
		break
	else:
		v -= 9 - i
		res += 1
print(res)


k = int(input())
n = input()
s = sum((int(x) for x in n))
n = sorted([9 - int(x) for x in n], reverse=True)
res = 0
for x in n:
	if s < k:
		res += 1
		s += x
print(res)


k = int(input())
n = input()
count = 0
num = 0
arr = [0 for i in range(10)]
for i in range(len(n)):
	num = int(n[i])
	count += num
	if count >= k:
		print(0)
		exit(0)
	arr[num] += 1
current = 0
c = 0
while count < k:
	if arr[current] == 0:
		for i in range(current + 1, 10):
			if arr[i] > 0:
				current = i
				break
	count = count - current + 9
	arr[current] -= 1
	c += 1
print(c)


import math
k = int(input())
n = input()
counter = [0 for x in range(0, 10)]
sum = 0
for x in n:
	sum += int(x)
	counter[int(x)] += 1
if sum >= k:
	print(0)
else:
	ans = 0
	for x in range(0, 10):
		if counter[x] == 0:
			continue
		if sum + counter[x] * (9 - x) >= k:
			ans += math.ceil((k - sum) / (9 - x))
			break
		else:
			ans += counter[x]
			sum += counter[x] * (9 - x)
	print(ans)


k = int(input())
n = input()
a = sum([int(i) for i in n])
n = sorted(n)
if a >= k:
	print(0)
else:
	cnt = 0
	for i in range(len(n)):
		if a >= k:
			break
		else:
			a = a + 9 - int(n[i])
			cnt += 1
	print(cnt)


k = int(input())
n = sorted(input())
for g in n:
	g = int(g)
	k -= g
cnt = 0
for g in n:
	if k <= 0:
		continue
	k += int(g)
	k -= 9
	cnt += 1
print(cnt)


k = int(input())
n = input()
n = list(map(int, list(n)))
m = list(set(n))
m1 = []
m.sort()
for i in range(len(m)):
	m1.append(n.count(m[i]))
count = 0
summa = sum(n)
if sum(n) >= k:
	print(0)
else:
	for i in range(len(m)):
		if k < (9 - m[i]) * m1[i] + summa:
			if (k - summa) % (9 - m[i]) != 0:
				count += (k - summa) // (9 - m[i]) + 1
				summa += ((k - summa) // (9 - m[i]) + 1) * (9 - m[i])
			else:
				count += (k - summa) // (9 - m[i])
				summa += (k - summa) // (9 - m[i]) * (9 - m[i])
		else:
			count += m1[i]
			summa += (9 - m[i]) * m1[i]
		if summa >= k:
			break
	print(count)


from math import ceil
k = int(input())
n = [el for el in input()]
n.sort()
sum = 0
for el in n:
	sum += int(el)
if sum >= k:
	print('0')
else:
	ans1 = 0
	sum1 = sum
	ans2 = 0
	sum2 = sum
	for i in range(len(n)):
		ans1 += 1
		sum1 -= int(n[i])
		sum1 += 9
		if sum1 >= k:
			break
	for i in range(len(n) - 1, -1, -1):
		ans2 += 1
		sum2 -= int(n[i])
		sum2 += 9
		if sum2 >= k:
			break
	print(min(ans1, ans2))


k = int(input())
n = sorted(map(int, list(input())))
cont = 0
suma = sum(n)
if suma < k:
	for i in range(len(n)):
		suma = suma + 9 - n[i]
		cont = cont + 1
		if suma >= k:
			break
print(cont)


k = int(input())
n = input()
out = 0
mas = sorted(list(map(int, n)))
S = 0
for i in range(len(mas)):
	S = S + mas[i]
if S < k:
	diff = k - S
	i = 0
	while diff > 0:
		diff = diff + mas[i] - 9
		i = i + 1
		out = out + 1
print(out)


k = int(input())
n = input()
n = [int(i) for i in n]
n = sorted(n)
s = sum(n)
if s >= k:
	print(0)
else:
	count = 0
	while s < k:
		s = s - n.pop(0) + 9
		count += 1
	print(count)


import sys
n = int(input())
k = list(str(input()))
a = []
for i in range(100000):
	a.append(0)
Klength = len(k)
ans = 0
for i in range(0, Klength):
	a[i] = int(k[i])
	ans += a[i]
a.sort()
sum = 0
if ans >= n:
	print('0')
	sys.exit(0)
for i in range(0, Klength):
	sum += 1
	ans += 9 - a[-Klength + i]
	if ans >= n:
		print(sum)
		break


def sortDigits(n):
	n = sorted(list(str(n)))
	n = ''.join(n)
	return n
k = int(input())
n = int(input())
n = sortDigits(n)
current_sum_digits = sum(map(int, list(n)))
next_ind = 0
changes = 0
while current_sum_digits < k:
	current_sum_digits -= int(n[next_ind])
	current_sum_digits += 9
	changes += 1
	next_ind += 1
print(changes)


a = int(input())
n = input()
digits = []
for c in n:
	digits.append(ord(c) - ord('0'))
digits.sort()
cur = sum(digits)
ans = 0
for d in digits:
	if cur < a:
		ans += 1
		cur += 9 - d
print(ans)


k = int(input())
s = input()
su = 0
has = [0] * 10
for i in s:
	su += int(i)
	has[int(i)] += 1
if su >= k:
	print(0)
else:
	i = 0
	ans = 0
	while i < 10 and su < k:
		if has[i] == 0:
			i += 1
		else:
			has[i] -= 1
			su += 9 - i
			ans += 1
	print(ans)


c = int(input())
l = sorted(list(map(int, input())))
x = 0
s = sum(l)
while s < c:
	s += 9 - l[x]
	x += 1
print(x)


k = int(input())
s = list(map(int, sorted(input())))
s.reverse()
res = 0
bad = k - sum(s)
while bad > 0:
	res += 1
	bad -= 9 - s[-1]
	s.pop()
print(res)


t = [0] * 10
k = int(input())
s = input()
ans = 0
for i in s:
	h = ord(i) - ord('0')
	ans += h
	t[h] += 1
if ans >= k:
	print(0)
else:
	k -= ans
	ans = 0
	for i in range(10):
		if (9 - i) * t[i] < k:
			k -= (9 - i) * t[i]
			ans += t[i]
		else:
			ans += k // (9 - i)
			if k % (9 - i) != 0:
				ans += 1
			break
	print(ans)


k = int(input())
n = sorted(list(input()))
s = 0
for i in range(len(n)):
	s += int(n[i])
kol = 0
for i in range(len(n)):
	if s >= k:
		break
	s += 9 - int(n[i])
	kol += 1
print(kol)


(k, nums) = (int(input()), sorted([int(x) for x in input()]))
suma = sum(nums)
counter = 0
while k - suma > 0:
	suma += 9 - nums[counter]
	counter += 1
print(counter)


k = int(input())
n = [int(i) for i in sorted(list(input()))]
i = 0
s = sum(n)
while i < len(n) and s < k:
	s += 9 - n[i]
	i += 1
print(i)


k = int(input())
n = input()
s = 0
for i in range(len(n)):
	s += int(n[i])
if s >= k:
	print(0)
else:
	l = [*n]
	l.sort()
	m = k - s
	i = 0
	while 1:
		a = 9 - int(l[i])
		m -= a
		i += 1
		if m <= 0:
			break
	print(i)


import sys
from math import ceil
k = int(input())
s = input()
su = 0
for i in s:
	su += int(i)
if su >= k:
	print(0)
else:
	s = sorted(s)
	yy = k - su
	res = 0
	for i in s:
		yy -= 9 - int(i)
		res += 1
		if yy <= 0:
			break
	print(res)


k = int(input().strip())
n = input().strip()
ln = len(n)
val_n = 0
cnt = {}
for x in range(10):
	cnt[str(x)] = 0
for x in range(ln):
	val_n += int(n[x])
	cnt[n[x]] += 1
if val_n >= k:
	print(0)
else:
	valsDiff = 0
	while k > val_n:
		for x in range(10):
			if cnt[str(x)] != 0:
				val_n -= x
				val_n += 9
				valsDiff += 1
				cnt[str(x)] -= 1
				break
	print(valsDiff)


k = int(input())
n = sorted(list(map(int, input())))
i = 0
s = sum(n)
while s < k:
	s += 9 - n[i]
	i += 1
print(i)


k = int(input())
s = input()
c = [s.count(chr(48 + i)) for i in range(10)]
ans = 0
total = sum(map(lambda c: ord(c) - 48, s))
digit = 0
while True:
	if total >= k:
		break
	while c[digit] == 0:
		digit += 1
	c[digit] -= 1
	total += 9 - digit
	ans += 1
print(ans)


k = int(input())
n = list(input())
s = 0
for j in range(len(n)):
	s = s + int(n[j])
if s >= k:
	print(0)
else:
	n.sort()
	c = 1
	for j in range(len(n)):
		if s + 9 - int(n[j]) < k:
			s = s + 9 - int(n[j])
			c = c + 1
		else:
			break
	print(c)


import decimal
k = decimal.Decimal(input())
n = input()
d_list = []
s = 0
for i in range(len(n)):
	d_list.append(decimal.Decimal(n[i]))
	s += decimal.Decimal(n[i])
d_list.sort()
if s >= k:
	print(0)
else:
	ans = 1
	for i in range(len(d_list)):
		if s - d_list[i] + 9 < k:
			ans += 1
			s = s - d_list[i] + 9
		else:
			break
	print(ans)


k = int(input())
n = sorted(map(int, input()))
ans = 0
k -= sum(n)
for num in n:
	if k <= 0:
		break
	ans += 1
	k -= 9 - num
print(ans)


k = int(input())
a = []
s = 0
for x in input():
	z = int(x)
	a.append(z)
	s += z
dx = k - s
a.sort()
ans = 0
if dx > 0:
	for i in range(len(a)):
		dx -= 9 - a[i]
		ans += 1
		if dx <= 0:
			break
else:
	for i in range(len(a) - 1, -1):
		dx += a[i]
		ans += 1
		if dx >= 0:
			break
print(ans)


k = int(input())
n = input()
digitos = []
for c in n:
	digitos.append(ord(c) - ord('0'))
digitos.sort()
cur = sum(digitos)
ans = 0
for d in digitos:
	if cur < k:
		cur += 9 - d
		ans += 1
print(ans)


from sys import stdin, stdout
k = int(stdin.readline().strip())
N = [int(x) for x in stdin.readline().strip()]
(current, change, size) = (0, 0, len(N))
for i in N:
	current += i
if current >= k:
	stdout.write('0')
else:
	N.sort()
	for i in range(size):
		if current < k:
			if N[i] != 9:
				change += 1
				current += 9 - N[i]
		else:
			break
	if current < k:
		stdout.write('0')
	else:
		stdout.write(str(change))


k = int(input())
a = list(input())
a.sort()
ans = 0
list_sum = 0
for i in a:
	list_sum += ord(i) - ord('0')
for i in a:
	if list_sum >= k:
		break
	list_sum += ord('9') - ord(i)
	ans += 1
print(ans)


k = int(input())
n = input()
sum = 0
B = 10 * [0]
for c in n:
	sum += int(c)
	B[int(c)] += 1
i = 0
cnt = 0
while sum < k:
	while B[i] == 0:
		i += 1
	sum += 9 - i
	B[i] -= 1
	cnt += 1
print(cnt)


x = int(input())
y = input()
z = 0
output = 0
lst = []
for i in range(len(y)):
	z += int(y[i])
	lst.append(int(y[i]))
if z >= x:
	output = 0
else:
	j = 0
	k = 0
	lst.sort()
	while j < len(lst):
		z += 9 - lst[j]
		output += 1
		if z >= x:
			break
		j += 1
print(output)


k = int(input())
num = input()
a = sorted(map(int, num))
S = sum(a)
res = 0
for (i, x) in enumerate(a):
	if S >= k:
		break
	if x != 9:
		res += 1
	S += 9 - x
print(res)


k = int(input())
n = int(input())
s = list(str(n))
n = str(n)
dig = []
for c in n:
	dig.append(ord(c) - ord('0'))
dig.sort()
su = sum(dig)
if k < su:
	print(0)
else:
	s.sort()
	ch = k - su
	mnt = 0
	i = 0
	while ch > 0:
		ch -= 9 - int(s[i])
		mnt += 1
		i += 1
	print(mnt)


a = [0] * 10
suma = 0
k = int(input())
n = input()
for i in n:
	suma += int(i)
	a[int(i)] += 1
suma = k - suma
if suma <= 0:
	print(0)
else:
	j = 0
	h = 0
	t = 0
	while h < suma:
		r = a[j] * (9 - j)
		h += r
		t += a[j]
		j += 1
	j -= 1
	while h >= suma:
		h -= 9 - j
		t -= 1
	if h == suma:
		print(t)
	else:
		print(t + 1)


k = int(input())
n = input()
a = []
for c in n:
	a.append(int(c))
a.sort()
b = sum(a)
ans = 0
for d in a:
	if b < k:
		b += 9 - d
		ans += 1
print(ans)


k = int(input())
sum = 0
n = input()
n = [i for i in n]
n.sort()
for i in n:
	sum += int(i)
iteration = 0
for i in range(len(n)):
	if sum >= k:
		break
	sum += 9 - int(n[i])
	iteration += 1
print(iteration)


k = int(input())
n = map(int, input())
n = sorted(n)
resp = 0
k -= sum(n)
for val in n:
	if k <= 0:
		break
	resp += 1
	x = 9 - val
	k -= x
print(resp)


k = int(input())
n = input()
data = []
for c in n:
	data.append(int(c))
data.sort()
sum_digits = sum(data)
if sum_digits >= k:
	print(0)
else:
	count = 0
	for i in data:
		sum_digits += 9 - i
		count += 1
		if sum_digits >= k:
			break
	print(count)


threshold = int(input())
I = [int(x) for x in input()]
I.sort()
number = 0
temp = sum(I)
while temp < threshold:
	temp = temp + (9 - I[number])
	number = number + 1
print(number)


k = int(input())
s = list(input())
x = sum(map(int, s))
if k <= x:
	print(0)
else:
	c = 1
	s.sort()
	for i in range(len(s)):
		if x + 9 - int(s[i]) < k:
			x = x + 9 - int(s[i])
			c += 1
		else:
			break
	print(c)


k = int(input())
n = input().split()[0]
s = 0
dic = dict()
dic[0] = 0
dic[1] = 0
dic[2] = 0
dic[3] = 0
dic[4] = 0
dic[5] = 0
dic[6] = 0
dic[7] = 0
dic[8] = 0
dic[9] = 0
for i in n:
	a = int(i)
	s += a
	dic[a] += 1
ans = 0
while s < k:
	ans += 1
	for i in range(10):
		if dic[i]:
			s += 9 - i
			dic[i] -= 1
			break
print(ans)


k = int(input())
n = input()
l = list(n)
for i in range(len(n)):
	l[i] = int(l[i])
l.sort()
s = sum(l)
a = 0
for i in range(len(n)):
	if s < k:
		s += 9 - l[i]
		a += 1
print(a)


k = int(input())
n = sorted([int(x) for x in list(input())])
k -= sum(n)
n = [9 - x for x in n]
c = 0
for x in range(len(n)):
	if k <= 0:
		break
	else:
		k -= n[x]
		c += 1
print(c)


k = int(input())
n = list(map(int, input()))
n.sort()
dif = k - sum(n)
(ans, i) = (0, 0)
while dif > 0:
	ans += 9 - n[i]
	dif -= 9 - n[i]
	i += 1
print(i)


k = int(input())
n = input()
orig_sum = 0
digs = [0] * 10
for i in n:
	ii = int(i)
	orig_sum += ii
	digs[ii] += 1
total = 0
i = 0
while orig_sum < k:
	if digs[i] > 0:
		nxt_dig = min(k - (orig_sum - i), 9)
		digs[i] -= 1
		digs[nxt_dig] += 1
		orig_sum -= i
		orig_sum += nxt_dig
		total += 1
	else:
		i += 1
print(total)


(k, list_n) = (int(input()), sorted(map(int, input()), reverse=True))
(sum_n, steps) = (sum(list_n), 0)
while sum_n < k:
	(sum_n, steps) = (sum_n + 9 - list_n.pop(), steps + 1)
print(steps)


k = int(input())
data = [0 for i in range(10)]
box = 0
for i in [int(i) for i in input()]:
	box += i
	data[i] += 1
ret = 0
for i in range(9):
	if box < k:
		for j in range(data[i]):
			if box < k:
				box += 9 - i
				ret += 1
			else:
				break
	else:
		break
print(ret)


k = int(input().split()[0])
n = list(map(int, input().rstrip()))
s = sum(n)
n.sort()
ans = 0
if s < k:
	for i in n:
		ans += 1
		s += 9 - i
		if s >= k:
			break
print(ans)


k = int(input())
n = list(map(int, input()))
s = sum(n)
n.sort()
i = 0
if s > k:
	print('0')
else:
	difference = k - s
	while difference > 0:
		difference = difference - (9 - n[i])
		i = i + 1
	print(i)


k = int(input())
n = list(input())
n.sort()
i = 0
x = 0
mysum = sum(list(map(int, n)))
tmp = 0
while True:
	mysum += tmp
	if mysum >= k:
		print(i)
		break
	try:
		if int(n[x]) != 9:
			tmp = 9 - int(n[x])
			n[x] = '9'
			i += 1
	except:
		pass
	x += 1


k = int(input())
n = input()
s = 0
for i in n:
	s += int(i)
if s >= k:
	print('0')
else:
	p = k - s
	l = sorted(n)
	c = 0
	curr = 0
	for i in range(len(l)):
		if curr >= p:
			break
		else:
			curr += 9 - int(l[i])
			c += 1
	print(c)


k = int(input())
n = list(map(int, sorted(input())))
s = sum(n)
idx = 0
res = 0
while k > s:
	s += 9 - n[idx]
	res += 1
	idx += 1
print(res)


k = int(input())
arr = sorted(list(map(int, input())))
s = 0
cambios = 0
for i in range(len(arr)):
	s += arr[i]
if s >= k:
	print(0)
else:
	m = 0
	for i in range(0, len(arr)):
		if s < k:
			s += 9 - arr[i]
			cambios += 1
		else:
			break
	print(cambios)


k = int(input())
n = int(input())
arr = list(map(int, list(str(n))))
n = sum(arr)
cnt = 0
arr.sort()
i = 0
ans = 0
if n > k:
	print(0)
else:
	while n < k:
		n += 9 - arr[i]
		ans += 1
		i += 1
	print(ans)


k = int(input())
l = list(input())
s = 0
p = 0
arr = []
for i in l:
	s = s + int(i)
q = 0
if s >= k:
	print(0)
else:
	t = k - s
	for i in l:
		arr.append(9 - int(i))
	arr.sort(reverse=True)
	for i in arr:
		p = p + 1
		q = q + i
		if q >= t:
			break
	print(p)


k = int(input())
n = input()
(l, sum, ans) = (len(n), 0, 0)
for i in range(0, l):
	sum += int(n[i])
a = sorted(n)
if sum >= k:
	print(0)
else:
	for i in range(0, l):
		sum += 9 - int(a[i])
		ans += 1
		if sum >= k:
			print(ans)
			exit()


k = int(input())
n = int(input())
sm = sum((int(x) for x in str(n)))
nums = sorted([int(x) for x in str(n)])
i = 0
while sm < k:
	i += 1
	sm += 9 - nums[i - 1]
	nums[i - 1] += 9 - nums[0]
print(i)


k = int(input())
n = input()
numbers = []
for i in n:
	numbers.append(ord(i) - ord('0'))
numbers.sort()
suma = sum(numbers)
cont = 0
for digit in numbers:
	if suma < k:
		suma += 9 - digit
		cont += 1
print(cont)


def solution(k, digits):
	digits.sort()
	s = sum(digits)
	diff = k - s
	c = 0
	for d in digits:
		if diff <= 0:
			break
		c += 1
		while d < 9:
			d += 1
			diff -= 1
	return c
k = int(input())
digits = list(map(int, input()))
print(solution(k, digits))


from collections import Counter
import math
(k, n) = (int(input()), input())
ns = Counter(n)
(cnt, s) = (0, 0)
for x in ns:
	s += int(x) * ns[x]
k -= s
if k <= 0:
	print(0)
	exit(0)
for x in sorted(ns):
	if math.ceil(k / (9 - int(x))) > ns[x] and int(x) != 9:
		cnt += ns[x]
		k -= ns[x] * (9 - int(x))
	else:
		cnt += math.ceil(k / (9 - int(x)))
		break
print(cnt)


k = int(input())
n = input()
sum = 0
for i in n:
	sum += int(i)
cnt = 0
n = sorted(n)
i = 0
while k > sum:
	if n[i] != '9':
		sum += 9 - int(n[i])
		cnt += 1
	i += 1
print(cnt)


k = int(input())
s = input()
sl = []
for i in s:
	sl += [int(i)]
sl.sort()
if sum(sl) >= k:
	print('0')
else:
	diff = k - sum(sl)
	ans = 0
	for i in sl:
		if diff <= 0:
			break
		diff -= abs(9 - i)
		ans += 1
	if diff <= 0:
		print(ans)


from sys import stdin, stdout
k = int(stdin.readline().rstrip())
n = stdin.readline().rstrip()
n = sorted(n)
ck = 0
for c in n:
	ck += ord(c) - ord('0')
if ck >= k:
	print(0)
else:
	rez = 0
	for c in n:
		ck += ord('9') - ord(c)
		rez += 1
		if ck >= k:
			print(rez)
			break


from collections import Counter
k = int(input())
n = Counter(map(int, input()))
t = sum(map(lambda x: x[0] * x[1], n.items()))
result = 0
for i in range(0, 11):
	if t >= k:
		print(result)
		break
	c = min(n[i], (k - t + 8 - i) // (9 - i))
	t += c * (9 - i)
	result += c


k = int(input())
n = list(input())
n.sort()
sum = 0
for i in n:
	sum += int(i)
m = 0
if k > sum:
	j = 0
	while sum < k:
		sum += 9 - int(n[j])
		j += 1
		m += 1
print(m)


k = int(input())
ll = input()
ll1 = [0] * 10
for i in range(len(ll)):
	ll1[int(ll[i])] += 1
summ = 0
for i in range(10):
	summ += ll1[i] * i
if summ >= k:
	print(0)
else:
	ans = 0
	p = k - summ
	for i in range(10):
		if ll1[i] != 0:
			for j in range(ll1[i]):
				if p <= 0:
					break
				else:
					p -= 9 - i
					ans += 1
	print(ans)


n = int(input())
t = list(input())
g = [int(i) for i in t]
p = sum(g)
g.sort()
if p >= n:
	print(0)
else:
	for k in range(len(g)):
		p = p + 9 - g[k]
		if p >= n:
			print(k + 1)
			break


(k, n) = (int(input()), sorted([int(i) for i in input()]))
(s, result) = (sum(n), 0)
while s < k:
	s += 9 - n[result]
	result += 1
print(result)


k = int(input())
cmd = input()
res = 0
a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for x in cmd:
	a[int(x)] += 1
	a[10] += int(x)
j = 0
while a[10] + (9 - j) * a[j] < k:
	a[10] += (9 - j) * a[j]
	res += a[j]
	j += 1
if k > a[10]:
	res1 = (k - a[10]) // (9 - j)
	a[10] += res1 * (9 - j)
	res += res1
print(res) if k <= a[10] else print(res + 1)


def main():
	K = int(input())
	N = input()
	n = sorted(list(map(int, N)))
	k2 = sum(n)
	if k2 >= K:
		ans = 0
	else:
		i = 0
		while k2 < K:
			j = 9 - n[i]
			n[i] = 9
			k2 += j
			i += 1
		ans = i
	print(ans)
main()


k = int(input())
s = list(input())
c = 0
ans = 0
for i in s:
	c += int(i)
if c >= k:
	exit(print(0))
else:
	s.sort()
	for i in s:
		if i != '9':
			c += 9
			c -= int(i)
			ans += 1
		if c >= k:
			exit(print(ans))


k = int(input())
n = input()
s = a = 0
for i in range(len(n)):
	s += int(n[i])
if s < k:
	n = sorted(n)
	t = k - s
	for i in range(0, len(n)):
		if int(n[i]) + t < 10:
			a += 1
			break
		b = 9 - int(n[i])
		t -= b
		a += 1
print(a)


n = int(input())
j = str(input())
u = list(j)
r = 0
for i in range(len(u)):
	r += int(u[i])
if n <= r:
	print(0)
else:
	i = 0
	sun = 0
	u.sort()
	while sun < abs(r - n) and i < len(u):
		sun += 9 - int(u[i])
		i += 1
	print(i)


k = int(input())
d = [0] * 10
s = input().strip()
for v in s:
	d[int(v)] += 1
res = 0
for (i, v) in enumerate(d):
	k -= i * v
if k < 0:
	k = 0
for (i, v) in enumerate(d):
	if k > (9 - i) * v:
		k -= (9 - i) * v
		res += v
	else:
		res += (k - 1) // (9 - i) + 1
		break
print(res)


n = int(input())
b = list(input())
for i in range(len(b)):
	b[i] = int(b[i])
z = sum(b)
if z >= n:
	print(0)
else:
	t = 0
	h = n - z
	te = 9 * [0]
	for i in range(9):
		te[i] = b.count(i)
	te2 = 9 * [0]
	for i in range(9):
		te2[i] = (9 - i) * te[i]
	te3 = 9 * [0]
	for i in range(9):
		te3[i] = sum(te2[:i + 1])
	while h > te3[t]:
		t += 1
	m = 0
	for i in range(t):
		m += te[i]
		h -= te2[i]
	if h % (9 - t) == 0:
		m += h // (9 - t)
	else:
		m += h // (9 - t) + 1
	print(m)


k = int(input())
n = str(input())
flag = 1
t = 0
for i in range(0, len(n)):
	t += int(n[i])
	if t >= k:
		flag = 0
		break
if flag == 0:
	print(0)
else:
	t = k - t
	dem = 0
	b = sorted(n)
	while t > 0:
		for i in range(0, len(b)):
			t -= 9 - int(b[i])
			dem += 1
			if t <= 0:
				break
	print(dem)


k = int(input())
n = [int(i) for i in input()]
s = sum(n)
n.sort()
i = 0
while i < len(n) and s < k:
	s += 9 - n[i]
	i += 1
print(i)


import sys, math
k = int(sys.stdin.readline())
n = sys.stdin.readline().rstrip()
cnt = 0
for i in n:
	cnt += int(i)
if cnt < k:
	diff = k - cnt
	n = list(n)
	n.sort()
	idx = 0
	res = 0
	while idx < len(n) and diff > 0:
		if n[idx] != '9':
			diff -= 9 - int(n[idx])
			res += 1
		idx += 1
	print(res)
else:
	print(0)


k = int(input())
n = int(input())
check = k - sum((int(i) for i in str(n)))
if check <= 0:
	print(0)
else:
	count = 0
	main = sorted([int(i) for i in str(n)])
	for i in range(len(main)):
		if main[i] + check > 9:
			check -= 9 - main[i]
			count += 1
		else:
			if check > 0:
				count += 1
			break
	print(count)


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
dgl = lambda : list(map(int, input()))
k = ii()
l = sorted(dgl())
sm = sum(l)
i = 0
while sm < k:
	sm += 9 - l[i]
	i += 1
print(i)


from collections import defaultdict
k = int(input())
n = [int(c) for c in input().strip()]
table = defaultdict(int)
for d in n:
	table[9 - d] += 1
total = sum(n)
num_digits = 0
while total < k:
	t = max(table.keys())
	count = table[t]
	del table[t]
	if total + count * t < k:
		total += count * t
		num_digits += count
	else:
		temp = (k - total) // t
		if total + temp * t < k:
			temp += 1
		num_digits += temp
		break
print(num_digits)


k = int(input())
s = input()
a = list()
for i in s:
	a.append(int(i))
a = sorted(a)
p = sum(a)
j = 0
while p < k:
	p = p + 9 - a[j]
	j = j + 1
print(j)


n = int(input())
num = int(input())
sum = 0
import queue as qq
q = []
for i in str(num):
	sum = sum + int(i)
	qq.heappush(q, int(i))
need = n - sum
ans = 0
while need > 0:
	need -= 9 - qq.heappop(q)
	ans += 1
print(ans)


k = int(input())
n = input()
s = sum(map(int, n))
a = 0
for i in sorted(n):
	if s >= k:
		break
	if s < k:
		s = s - int(i) + 9
		a += 1
print(a)


k = int(input())
s = str(input())
t = 0
for c in s:
	t += int(c)
if t > k or k - t == 0:
	print(0)
else:
	diff = k - t
	ans = 0
	s = sorted(s)
	for c in s:
		if int(c) != 9:
			ans += 1
			diff -= 9 - int(c)
		if diff <= 0:
			break
	print(ans)


a = int(input())
digits = sorted(map(int, list(input())))
b = sum(digits)
n = 0
while b < a:
	b += 9 - digits[n]
	n += 1
print(n)


(k, n) = (int(input()), list(input()))
n.sort()
S = sum([int(i) for i in n])
i = 0
while S < k:
	S += 9 - int(n[i])
	i += 1
print(i)


k = int(input())
n = input()
d = [int(i) for i in n]
d.sort()
s = sum(d)
movements = 0
for i in d:
	if s < k:
		s += 9 - i
		movements += 1
print(movements)


k = int(input())
n = input()

def digitsum(s):
	su = 0
	for i in range(len(s)):
		su += int(s[i])
	return su
dig = digitsum(n)
maxpos = 9 * len(n)
n = list(map(int, n))
n.sort()
if dig >= k:
	print(0)
else:
	rep = 0
	for i in range(len(n)):
		diff = 9 - int(n[i])
		dig = dig + diff
		rep += 1
		if dig >= k:
			break
	print(rep)


k = int(input())
n = list(map(int, list(input())))
n.sort()
g = sum(n)
i = 0
while g < k:
	while n[i] + 1 < 10:
		n[i] += 1
		g += 1
	i += 1
print(i)


n = int(input())
s = input()
sum = 0
l = []
for i in s:
	sum += int(i)
	l.append(int(i))
l.sort()
if sum >= n:
	print('0')
else:
	a = 0
	b = n - sum
	k = 0
	while b > 0:
		if l[k] + b <= 9:
			a += 1
			b = 0
		else:
			b -= 9 - l[k]
			a += 1
		k += 1
	print(a)


k = int(input())
m = input()
m = m.replace('', ' ')
a = sorted(map(int, m.split()))
l = sum(a)
if l >= k:
	print(0)
else:
	x = 0
	for i in a:
		if l >= k:
			break
		else:
			l += 9 - i
			x += 1
	print(x)


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import re

def tup():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
from math import log2, sqrt
from collections import defaultdict
k = I()
n = S()
arr = sorted(list(map(int, n)))
cnt = sum(arr)
ans = 0
for i in arr:
	if cnt < k:
		cnt += 9 - i
		ans += 1
print(ans)


N = int(input())
X = list(map(int, input()))
(SUM, Digits) = (sum(X), 0)
for i in sorted(X):
	if N - SUM <= 0:
		break
	elif i != 9:
		SUM += 9 - i
		Digits += 1
print(Digits)


k = int(input())
n = input()
lst = list(map(int, n))
summation = sum(lst)
if summation >= k:
	print(0)
else:
	lst.sort()
	count = 0
	while summation < k:
		summation += 9 - lst[count]
		count += 1
	print(count)


k = int(input())
n = list(input())
n.sort()
total = 0
answer = 0
for x in n:
	total += int(x)
i = 0
while total < k:
	total += 9 - int(n[i])
	answer += 1
	i += 1
print(answer)


def main():
	(k,) = read()
	n = input()
	s = [0] * 10
	for c in n:
		s[ord(c) - 48] += 1
	k -= sum((i * s[i] for i in range(10)))
	ct = 0
	for i in range(9):
		if k <= 0:
			return ct
		tm = min(s[i], (k + 9 - i - 1) // (9 - i))
		ct += tm
		k -= tm * (9 - i)
	return ct

def read(callback=int):
	return list(map(callback, input().strip().split()))

def write(value, end='\n'):
	if value is None:
		return
	try:
		if not isinstance(value, str):
			value = ' '.join(map(str, value))
	except:
		pass
	print(value, end=end)
write(main())


k = int(input())
n = list(map(int, input()))
x = sum(n)
n = list(map(str, n))
if k > x:
	d = k - x
	n.sort()
	m = len(n)
	c = 0
	i = 0
	while i < m and d > 0:
		a = 9 - int(n[i])
		if d >= a:
			d -= a
		else:
			a = d
			d = 0
		n[i] = str(int(n[i]) + a)
		c += 1
		i += 1
	print(c)
else:
	print(0)


k = int(input())
l = int(input())
l = str(l)
l = list(map(int, l))
l = sorted(l)
suma = sum(l)
d = 0
if suma >= k:
	print(0)
else:
	for i in range(0, len(l)):
		d += 1
		suma += 9 - l[i]
		if suma >= k:
			break
	print(d)


n = int(input())
x = input()
y = ''.join(sorted(x))
s = 0
for i in y:
	s = s + int(i)
diff = n - s
c = 0
for i in y:
	if diff > 0:
		diff = diff - (9 - int(i))
		c = c + 1
print(c)


k = int(input())
n = int(input())
p = list(str(n))
p.sort()
ans = 0
tot = 0
for ele in p:
	tot += int(ele)
for ele in p:
	if tot < k:
		tot += 9 - int(ele)
		ans += 1
print(ans)


k = int(input())
n = list(map(int, input().rstrip()))
tot = sum(n)
n.sort()
count = 0
if tot < k:
	for i in n:
		tot += 9 - i
		count += 1
		if tot >= k:
			break
print(count)


k = int(input())
s = list(input())
s = sorted(s)
sint = list(map(int, s))
ssum = sum(sint)
if ssum >= k:
	print('0')
else:
	ssum = ssum - k
	i = 0
	c = 0
	while i < len(s):
		ssum = ssum + 9 - sint[i]
		c += 1
		if ssum >= 0:
			break
		i += 1
	print(c)


import math
k = int(input())
n = input()
a = [0] * 10
s = 0
for i in n:
	a[int(i)] += 1
	s += int(i)
if s >= k:
	print(0)
else:
	cnt = 0
	diff = k - s
	for i in range(9):
		if diff > 0:
			cost = 9 - i
			need = math.ceil(diff / cost)
			if need > a[i]:
				diff -= a[i] * cost
				cnt += a[i]
				a[i] = 0
			else:
				diff -= need * cost
				a[i] -= need
				cnt += need
	print(cnt)


k = int(input())
n = input()
_sum = 0
for i in n:
	_sum += int(i)
temp = []
temp.extend(n)
temp.sort()
count = 0
i = 0
while k > _sum:
	if temp[i] != '9':
		_sum += 9 - int(temp[i])
		count += 1
	i += 1
print(count)


k = int(input())
d = list(map(int, list(input())))
d.sort()
l = sum(d)
i = 0
while l < k:
	l += 9 - d[i]
	i += 1
print(i)


k = int(input())
n = input()
s = sum(list(map(int, n)))
if s >= k:
	print(0)
else:
	d = [0] * 9
	for i in range(0, 9):
		d[i] = n.count(str(i))
	c = 0
	dif = k - s
	for i in range(0, 9):
		if dif > d[i] * (9 - i):
			dif -= d[i] * (9 - i)
			c += d[i]
		else:
			cur = dif // (9 - i)
			if dif % (9 - i) != 0:
				cur += 1
			c += cur
			break
	print(c)


k = int(input())
n = input()
dg = []
for digit in n:
	dg.append(ord(digit) - ord('0'))
dg.sort()
tot = sum(dg)
ans = 0
for i in dg:
	if tot < k:
		tot += 9 - i
		ans += 1
print(ans)


k = int(input())
ins = sorted([int(x) for x in input()])
sums = sum(ins)
i = 0
while sums < k:
	sums += 9 - ins[i]
	i += 1
print(i)


def getSmallestDifferNum(n, k):
	res = 0
	visited = {}
	for i in range(len(n)):
		num = int(n[i])
		if visited.get(num):
			visited[num] += 1
		else:
			visited[num] = 1
		res += num
		if res >= k:
			return 0
	acum = 0
	num_digit = 0
	for i in range(10):
		if visited.get(i):
			j = 0
			while j < visited.get(i):
				acum += 9 - i
				num_digit += 1
				if acum + res >= k:
					return num_digit
				j += 1
	return num_digit
k = int(input())
n = input()
print(getSmallestDifferNum(n, k))


k = int(input())
n = input()
digit = [0] * 10
for c in n:
	digit[int(c)] += 1
dsum = sum((i * digit[i] for i in range(10)))
i = 0
change = 0
while dsum < k:
	if digit[i] == 0:
		i += 1
		continue
	digit[i] -= 1
	digit[9] += 1
	change += 1
	dsum += 9 - i
print(change)


k = int(input())
n = input()
x = [int(y) for y in n]
sum = 0
ans = 0
for no in x:
	sum += no
if sum >= k:
	print(0)
else:
	toadd = k - sum
	x.sort()
	for no in x:
		av = 9 - no
		toadd = toadd - av
		ans += 1
		if toadd <= 0:
			break
	print(ans)


n = int(input())
a = list(map(int, list(input())))
su = sum(a)
a.sort()
m = len(a)
cou = 0
for i in range(m):
	if a[i] != 9 and su < n:
		su += 9 - a[i]
		cou += 1
	elif su >= n:
		break
print(cou)


k = int(input())
x = [0] * 10
for c in input():
	c = int(c)
	k -= c
	x[c] += 1
t = 0
i = 0
while k > 0 and i != 9:
	c = min(k // (9 - i) + (1 if k % (9 - i) != 0 else 0), x[i])
	k -= c * (9 - i)
	i += 1
	t += c
print(t)


k = int(input())
board = sorted([int(x) for x in list(input())])
i = 0
total = sum(board)
while total < k:
	total += 9 - board[i]
	i += 1
print(i)


k = int(input())
n = input()
ns = list(map(int, list(n)))
ns.sort()
ss = sum(ns)
i = 0
while ss < k:
	ss += 9 - ns[i]
	i += 1
print(i)


k = int(input())
n = sorted(list(map(int, list(input()))))
s = sum(n)
count = 0
i = 0
for x in n:
	if s < k:
		s += 9 - x
		count += 1
	else:
		break
print(count)


k = int(input())
n = sorted(list(input()))[::-1]
suma = 0
t = len(n)
i = 0
while i != t and suma < k:
	suma += int(n[i])
	i += 1
if suma < k:
	j = 0
	while suma < k:
		suma = suma - int(n[t - 1 - j]) + 9
		j += 1
	print(j)
else:
	print(0)


k = int(input())
l = sorted(list(map(int, list(input()))))
kn = sum(l)
c = 0
while kn < k:
	kn += 9 - l.pop(0)
	c += 1
print(c)


k = int(input())
n = input()
l = []
s = 0
for i in range(len(n)):
	l.append(int(n[i]))
	s += int(n[i])
l.sort()
if s >= k:
	print(0)
else:
	term = 0
	while s < k:
		s += 9 - l[term]
		term += 1
	print(term)


I = lambda : list(map(int, input().split()))
k = int(input())
n = [9] + sorted(map(int, input()))
r = k - sum(n[1:])
for (i, nn) in enumerate(n):
	r -= 9 - nn
	if r < 1:
		print(i)
		break


from sys import stdin, stdout

def main():
	k = int(stdin.readline().strip())
	n = stdin.readline().strip()
	n = sorted(n)
	total = 0
	for c in n:
		d = ord(c) - 48
		total += d
	ans = 0
	for c in n:
		if total >= k:
			break
		d = ord(c) - 48
		total = total - d + 9
		ans += 1
	stdout.write(str(ans) + '\n')
main()


from math import ceil
k = int(input())
digits = [0] * 10
n = input()
s = 0
for i in n:
	digits[int(i)] += 1
	s += int(i)
i = 0
cnt = 0
while s < k and i < 10:
	if s + (9 - i) * digits[i] < k:
		s += (9 - i) * digits[i]
		cnt += digits[i]
		i += 1
	else:
		cnt += ceil((k - s) / (9 - i))
		s = k
print(cnt)


def count_sort(a):
	counts = [0 for i in range(10)]
	for digit in a:
		counts[int(digit)] += 1
	return counts

def summ_by_count(counts):
	summ = 0
	for (digit, count) in enumerate(counts):
		summ += digit * count
	return summ

def main():
	k = int(input())
	n = input()
	counts = count_sort(n)
	summ_n = summ_by_count(counts)
	current_digit = 0
	digits_to_change = 0
	while summ_n < k:
		if counts[current_digit] == 0:
			current_digit += 1
			continue
		counts[current_digit] -= 1
		summ_n += 9 - current_digit
		digits_to_change += 1
	print(digits_to_change)
main()


s = int(input())
n = list(map(int, input()))
w = sorted(n)
summing = sum(w)
if summing >= s:
	print('0')
else:
	i = 0
	while summing < s:
		add = 9 - w[i]
		summing += add
		i += 1
	print(i)


k = int(input())
n = int(input())
li = [int(d) for d in str(n)]
s = sum(li)
li.sort()
result = 0
for item in li:
	if s >= k:
		break
	result += 1
	s += 9 - item
print(result)


k = int(input())
n = input()
nn = []
kk = []
for num in n:
	nn.append(int(num))
dif = k - sum(nn)
nOrdenado = sorted(nn)
minnum = 0
while dif > 0:
	temp = nOrdenado[minnum]
	dif -= 9 - temp
	minnum += 1
print(minnum)


x = int(input())
y = list(map(int, input()))
s = sum(y)
y.sort()
f = 0
for i in y:
	if x > s:
		s += 9 - i
		f += 1
print(f)


k = int(input())
n = input()
l = []
for i in range(len(n)):
	l.append(int(n[i]))
l = sorted(l)
i = 0
m = sum(l)
y = 0
while 1 == 1:
	if m + y >= k:
		print(i)
		break
	else:
		y = y + 9 - l[i]
		i = i + 1


k = int(input())
n = input()
numeros = []
for m in n:
	numeros.append(ord(m) - ord('0'))
numeros.sort()
act = sum(numeros)
respuesta = 0
for dif in numeros:
	if act < k:
		act += 9 - dif
		respuesta += 1
print(respuesta)


k = int(input())
n = input()
arr = []
for i in n:
	arr.append(int(i))
arr.sort()
summ = sum(arr)
count = 0
if summ < k:
	for i in arr:
		summ += 9 - i
		count += 1
		if summ >= k:
			break
	print(count)
else:
	print(0)


k = int(input())
n = sorted(map(int, input()))
s = sum(n)
ans = 0
nk = 0
k = k - s
while nk < k and ans < len(n):
	nk += 9 - n[ans]
	ans += 1
print(ans)


(k, digits) = (int(input()), sorted(map(int, input()), reverse=True))
(sum_, steps) = (sum(digits), 0)
while sum_ < k:
	(sum_, steps) = (sum_ + 9 - digits.pop(), steps + 1)
print(steps)


k = int(input())
n = input()
k1 = 0
a = []
for i in n:
	k1 += int(i)
	a.append(int(i))
if k1 >= k:
	print(0)
else:
	a.sort()
	s = 0
	for i in a:
		k1 += 9 - i
		s += 1
		if k1 >= k:
			break
	print(s)


from sys import stdin, stdout
k = int(stdin.readline().rstrip())
n = int(stdin.readline().rstrip())
nList = list(map(int, list(str(n))))
nList.sort()
currentSum = sum(nList)
i = 0
while currentSum < k:
	currentSum += 9 - nList[i]
	i += 1
print(i)


import math
k = int(input())
n = input()
n_digits = sorted(list(map(int, list(n))), reverse=True)
digit = 0
count = 0
if sum(n_digits) >= k:
	print(0)
else:
	while sum(n_digits) < k:
		rem_no = k - sum(n_digits)
		digit_index = [i for i in range(0, len(n_digits)) if n_digits[i] == digit]
		digit_count = len(digit_index)
		increment_value = digit_count * (9 - digit)
		if increment_value < rem_no:
			for i in digit_index:
				n_digits[i] = 9
			count += digit_count
		else:
			req = math.ceil(rem_no / (9 - digit))
			for i in range(0, req):
				n_digits[digit_index[i]] = 9
			count += req
		digit += 1
	print(count)


s = int(input())
t = list(map(int, list(input())))
if sum(t) >= s:
	print(0)
else:
	d = s - sum(t)
	t.sort()
	for i in range(len(t)):
		d -= 9 - t[i]
		if d <= 0:
			print(i + 1)
			exit()


k = int(input())
nn = input()
ll = [0 for i in range(10)]
n = map(int, nn)
ssum = 0
for i in n:
	ssum = ssum + i
	ll[i] = ll[i] + 1
if ssum >= k:
	print('0')
else:
	val = k - ssum
	cnt = 0
	i = 0
	while val > 0:
		if ll[i] > 0:
			val = val - (9 - i)
			cnt = cnt + 1
			ll[i] = ll[i] - 1
		else:
			i = i + 1
	print(cnt)


k = int(input())
n = int(input())
s = str(n)
arr = [int(x) for x in s]
arr.sort()
su = 0
for i in range(len(arr)):
	su += arr[i]
tf = 0
for i in range(len(arr)):
	if su >= k:
		break
	else:
		su += 9 - arr[i]
		tf += 1
print(tf)


k = int(input())
n = input()
l = []
sum = 0
for i in n:
	sum += int(i)
	l.append(int(i))
l.sort()
counter = 0
for i in l:
	if sum >= k:
		break
	sum += 9 - i
	counter += 1
print(counter)


def digit_list(i):
	return [int(j) for j in str(i)]
k = int(input())
n = int(input())
sum_n = sum(digit_list(n))
if sum_n >= k:
	print(0)
else:
	differ = k - sum_n
	n_list = digit_list(n)
	n_list.sort()
	total = 0
	for i in range(len(n_list)):
		total += 9 - n_list[i]
		if total >= differ:
			print(i + 1)
			break


def parse(k, m):
	arr = [int(d) for d in str(m)]
	length = len(arr)
	total = sum(arr)
	if total >= k:
		return 0
	arr.sort()
	changed = 0
	k -= total
	while k > 0 and changed < length:
		k -= 9 - arr[changed]
		changed += 1
	return changed
k = int(input())
m = int(input())
print(parse(k, m))


k = int(input())
n = list(map(int, list(input())))
a = [n.count(i) for i in range(10)]
s = sum(n)
ans = 0
i = 0
while s < k:
	while a[i] > 0 and s < k:
		a[i] -= 1
		a[9] += 1
		s += 9 - i
		ans += 1
	i += 1
print(ans)


k = int(input())
l = sorted([int(i) for i in input()])
(a, s) = (0, sum(l))
j = 0
while s < k:
	s += 9 - l[j]
	a += 1
	j += 1
print(a)


def read():
	return [int(e) for e in input()]
k = int(input())
num = read()
num.sort()
s = sum(num)
i = 0
if s < k:
	for e in num:
		i += 1
		s += 9 - e
		if s >= k:
			break
print(i)


k = int(input().strip())
n = [int(digit) for digit in input().strip()]
current_sum = sum(n)
if current_sum >= k:
	print(0)
else:
	n.sort()
	for (idx, item) in enumerate(n):
		current_sum += abs(9 - item)
		if current_sum >= k:
			print(idx + 1)
			break


import math
k = int(input())
n = input()
sum = 0
v = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(len(n)):
	d = int(n[i])
	sum += d
	v[d] += 1
ans = 0
if sum < k:
	r = k - sum
	for i in range(9):
		c = min(int(math.ceil(r / (9 - i))), v[i])
		r = max(0, r - (9 - i) * c)
		ans += c
		if r == 0:
			break
print(ans)


K = int(input())
number = input()
number = list(number)
number = [int(i) for i in number]
number.sort()
sum = 0
for i in number:
	sum += i
j = 0
while sum < K:
	sum = sum + 9 - number[j]
	j += 1
print(j)


sum = int(input())
b = input()
l = []
count = 0
for letter in b:
	l.append(int(letter))
	count += int(letter)
l = sorted(l)
a = 1
count2 = 0
count3 = 0
if count - sum >= 0:
	print(0)
else:
	for el in l:
		if count2 < sum - count and el != 9:
			count2 += 9 - el
			count3 += 1
	print(count3)


k = int(input())
inp = input()
n = []
for val in inp:
	n.append(int(val))
n.sort()
sumval = sum(n)
counter = 0
for val in n:
	if sumval < k:
		sumval += 9 - val
		counter += 1
	else:
		break
print(counter)


k = int(input())
num = [int(i) for i in input()]
num.sort()
q = k - sum(num)
w = 0
while q > 0:
	q -= 9 - num[w]
	w += 1
print(w)


k = int(input())
n = input()
sum = 0
ans = 0
for i in n:
	sum += int(i)
if sum >= k:
	print(ans)
	exit()
for i in range(10):
	for j in n:
		if int(j) == i:
			sum += 9 - i
			ans += 1
			j = '9'
			if sum >= k:
				print(ans)
				exit()


A = int(input())
B = input()
from collections import Counter
temp = sum((int(x) for x in B))
if temp >= A:
	print(0)
if temp < A:
	temp1 = A - temp
	temp2 = Counter(B)
	I = [temp2['0'] * 9, temp2['1'] * 8, temp2['2'] * 7, temp2['3'] * 6, temp2['4'] * 5, temp2['5'] * 4, temp2['6'] * 3, temp2['7'] * 2, temp2['8'] * 1]
	H = [I[0], I[0] + I[1], I[0] + I[1] + I[2], I[0] + I[1] + I[2] + I[3], I[0] + I[1] + I[2] + I[3] + I[4], I[0] + I[1] + I[2] + I[3] + I[4] + I[5], I[0] + I[1] + I[2] + I[3] + I[4] + I[5] + I[6], I[0] + I[1] + I[2] + I[3] + I[4] + I[5] + I[6] + I[7], I[0] + I[1] + I[2] + I[3] + I[4] + I[5] + I[6] + I[7] + I[8]]
	if temp1 <= H[0]:
		temp3 = (temp1 + 8) // 9
	elif temp1 <= H[1]:
		temp3 = (temp1 - H[0] + 7) // 8 + temp2['0']
	elif temp1 <= H[2]:
		temp3 = (temp1 - H[1] + 6) // 7 + temp2['0'] + temp2['1']
	elif temp1 <= H[3]:
		temp3 = (temp1 - H[2] + 5) // 6 + temp2['0'] + temp2['1'] + temp2['2']
	elif temp1 <= H[4]:
		temp3 = (temp1 - H[3] + 4) // 5 + temp2['0'] + temp2['1'] + temp2['2'] + temp2['3']
	elif temp1 <= H[5]:
		temp3 = (temp1 - H[4] + 3) // 4 + temp2['0'] + temp2['1'] + temp2['2'] + temp2['3'] + temp2['4']
	elif temp1 <= H[6]:
		temp3 = (temp1 - H[5] + 2) // 3 + temp2['0'] + temp2['1'] + temp2['2'] + temp2['3'] + temp2['4'] + temp2['5']
	elif temp1 <= H[7]:
		temp3 = (temp1 - H[6] + 1) // 2 + temp2['0'] + temp2['1'] + temp2['2'] + temp2['3'] + temp2['4'] + temp2['5'] + temp2['6']
	elif temp1 <= H[8]:
		temp3 = temp1 - H[7] + temp2['0'] + temp2['1'] + temp2['2'] + temp2['3'] + temp2['4'] + temp2['5'] + temp2['6'] + temp2['7']
	print(temp3)


k = int(input())
s = str(input())
digits = []
for i in range(0, len(s), 1):
	digits.append(int(s[i]))
digits.sort()
cur = sum(digits)
ans = 0
for i in digits:
	if cur < k:
		cur += 9 - i
		ans += 1
print(ans)


k = int(input())
l = list(input())
l.sort()
s = 0
z = 0
for i in l:
	s = s + int(i) - int('0')
if s >= k:
	print(0)
else:
	j = 0
	while s < k:
		if l[j] != 9:
			s = s + int(9) - int(l[j])
			z = z + 1
		j = j + 1
	print(z)


def main():
	k = int(input())
	n = [int(i) for i in input()]
	s = sum(n)
	n.sort()
	an = 0
	sm = 0
	if s >= k:
		print(0)
	else:
		while sm < k - s:
			sm += 9 - n[an]
			an += 1
		print(an)
main()


n = int(input())
a = list(map(int, list(input())))
s = sum(a)
count = 0
a.sort()
for i in range(len(a)):
	if s >= n:
		break
	s = s + 9 - a[i]
	count += 1
print(count)


k = int(input())
s = [int(x) for x in input()]
s.sort()
diff = k - sum(s)
cnt = 0
for x in s:
	if diff <= 0:
		break
	diff -= 9 - x
	cnt += 1
print(cnt)


n = int(input())
s = input().rstrip()
x = list(s)
V = 0
for i in range(0, len(x)):
	V += int(x[i])
if V >= n:
	print(0)
else:
	x.sort(key=int)
	G = 0
	for i in range(0, len(x)):
		A = 9 - int(x[i])
		V += A
		G += 1
		if V >= n:
			break
	print(G)


k = int(input())
s = input()
digits = []
for c in s:
	digits.append(ord(c) - ord('0'))
digits.sort()
(current, result) = (sum(digits), 0)
for d in digits:
	if current < k:
		current += 9 - d
		result += 1
print(result)


k = int(input())
n = list(input())
for i in range(len(n)):
	n[i] = int(n[i])
n = sorted(n)
i = 0
d = sum(n)
while d < k:
	d += 9 - n[i]
	i += 1
print(i)


k = int(input())
n = input()
sum_ = 0
A = [0 for i in range(10)]
for i in n:
	sum_ += int(i)
	A[int(i)] += 1
delta = k - sum_
res = 0
i = 0
while delta > 0:
	if A[i] != 0:
		A[i] -= 1
		delta -= 9 - i
		res += 1
		continue
	i += 1
print(res)


k = int(input())
x = sorted(map(int, list(input())))
s = sum(x)
if s >= k:
	print('0')
	exit()
count = 0
for i in range(len(x)):
	m = 9 - x[i]
	x[i] = 9
	count += 1
	s += m
	if s >= k:
		print(count)
		exit()


import sys
k = int(input())
N = int(input())
if sum([int(x) for x in str(N)]) >= k:
	print(0)
else:
	L = list(map(int, list(str(N))))
	Sum = sum(L)
	L.sort()
	x = len(L)
	for i in range(x):
		if 9 - L[i] >= k - Sum:
			print(i + 1)
			sys.exit(0)
		else:
			Sum += 9 - L[i]


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
k = r()
a = list(map(int, input()))
b = []
sumi = a[0]
b.append(9 - a[0])
n = len(a)
for i in range(1, n):
	sumi += a[i]
	b.append(9 - a[i])
if k <= sumi:
	print(0)
else:
	change = k - sumi
	b.sort(reverse=True)
	i = 0
	while change > 0 and i < n:
		change -= b[i]
		i += 1
	print(i)


k = int(input())
n = input()
cur_sum = sum(map(int, n))
c = 0
for i in sorted(n):
	if cur_sum >= k:
		break
	if i != '9':
		cur_sum = cur_sum - int(i) + 9
		c += 1
print(c)


k = eval(input())
n = input()
array = []
for char in n:
	array.append(ord(char) - ord('0'))
array.sort()
value = sum(array)
count = 0
for i in array:
	if value < k:
		value += 9 - i
		count += 1
print(count)


k = int(input())
n = input()
c = [0] * 10
summ = 0
for s in n:
	c[int(s)] += 1
	summ += int(s)
zam = 0
for i in range(0, 9):
	if summ >= k:
		break
	if k - summ - c[i] * (9 - i) >= 0:
		zam += c[i]
		summ += c[i] * (9 - i)
	else:
		temp = (k - summ) // (9 - i)
		if (k - summ) % (9 - i) > 0:
			temp += 1
		summ += temp * (9 - i)
		zam += temp
print(zam)


k1 = int(input())
n = input()
sum = 0
list1 = []
list2 = []
for j in range(len(n)):
	sum += ord(n[j]) - ord('0')
	list1.append(ord(n[j]) - ord('0'))
list1.sort()
list2.append(9 - list1[0])
for k in range(len(list1)):
	list1[k] = 9 - list1[k]
	if k != 0:
		list2.append(list1[k] + list2[k - 1])
if sum >= k1:
	print('0')
else:
	for j in range(len(list2)):
		if list2[j] >= k1 - sum:
			print(j + 1)
			break


from collections import Counter
import math

class CodeforcesTask835BSolution:

	def __init__(self):
		self.result = ''
		self.k = 0
		self.n = 0

	def read_input(self):
		self.k = int(input())
		self.n = input()

	def process_task(self):
		digits = [int(x) for x in self.n]
		real_k = sum(digits)
		cnt = Counter(digits)
		if real_k >= self.k:
			self.result = '0'
		else:
			lvl = 0
			diff = 0
			while real_k < self.k:
				df_lvl = 9 - lvl
				if cnt[lvl] * df_lvl >= self.k - real_k:
					diff += math.ceil((self.k - real_k) / df_lvl)
					real_k = self.k
				else:
					diff += cnt[lvl]
					real_k += cnt[lvl] * df_lvl
				lvl += 1
			self.result = str(diff)

	def get_result(self):
		return self.result
Solution = CodeforcesTask835BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


a = int(input())
b = sorted(list(map(int, list(input()))))
s = sum(b)
if a > s:
	count = 0
	for i in b:
		if s < a:
			s += 9 - int(i)
			count += 1
		else:
			break
	print(count)
else:
	print('0')


k = int(input())
n = input()
sum = 0
pt = []
for i in range(len(n)):
	a = 9 - int(n[i])
	pt.append(a)
	sum += int(n[i])
diff = k - sum
pt.sort()
pt.reverse()
if diff <= 0:
	print('0')
else:
	for i in range(len(pt)):
		diff -= pt[i]
		if diff <= 0:
			break
	print(i + 1)


k = int(input().strip())
n = list(map(int, input().strip()))
sumN = sum(n)
if sumN >= k:
	print(0)
else:
	n.sort()
	i = 0
	c = 0
	while sumN < k:
		sumN += 9 - n[i]
		c += 1
		i += 1
	print(c)


def count_sort(n):
	b = [0] * 10
	for i in n:
		b[int(i)] += 1
	return (b, b[0] * 0 + b[1] * 1 + b[2] * 2 + b[3] * 3 + b[4] * 4 + b[5] * 5 + b[6] * 6 + b[7] * 7 + b[8] * 8 + b[9] * 9)
k = int(input())
n = input()
(b, sm) = count_sort(n)
d = 0
while sm < k:
	for i in range(10):
		if b[i] > 0:
			b[i] -= 1
			b[9] += 1
			d += 1
			sm = b[0] * 0 + b[1] * 1 + b[2] * 2 + b[3] * 3 + b[4] * 4 + b[5] * 5 + b[6] * 6 + b[7] * 7 + b[8] * 8 + b[9] * 9
			break
print(d)


k = int(input())
n = input()
val = sorted([int(c) for c in n])
s = sum(val)
c = 0
while s < k:
	s += 9 - val[c]
	c += 1
print(c)


k = int(input())
a = input()
s = 0
b = []
for n in a:
	s += int(n)
	b.append(int(n))
b.sort()
if s > k:
	print(0)
else:
	r = k - s
	cnt = 0
	while r > 0:
		r -= 9 - b[cnt]
		cnt += 1
	print(cnt)


t = int(input())
s = input()
numbers = [0] * 10
sum = 0
for i in s:
	numbers[int(i)] += 1
	sum += int(i)
if sum >= t:
	print(0)
else:
	ans = 0
	for i in range(0, 10):
		if numbers[i] == 0:
			continue
		for j in range(1, numbers[i] + 1):
			if sum + (9 - i) * j >= t:
				sum += (9 - i) * j
				ans += j
				break
		if sum >= t:
			break
		else:
			sum += (9 - i) * numbers[i]
			ans += numbers[i]
	print(ans)


k = int(input())
n = input()
s = 0
l = [0] * 10
for i in n:
	t = int(i)
	s += t
	l[t] += 1
if s < k:
	t = 0
	flag = 1
	for i in range(10):
		if l[i] == 0:
			pass
		else:
			while l[i] and flag:
				l[i] -= 1
				s += 9 - i
				t += 1
				if s >= k:
					print(t)
					flag = 0
else:
	print(0)


k = int(input())
n = int(input())
num = str(n)
sumOfDigits = sum([int(x) for x in list(num)])
if sumOfDigits >= k:
	print(0)
else:
	diff = k - sumOfDigits
	res = 0
	sortedN = sorted([int(x) for x in list(num)])
	index = 0
	while diff > 0 and index < len(sortedN):
		diff -= 9 - sortedN[index]
		res += 1
		index += 1
	print(res)


k = int(input())
n = input()
sum = 0
count = [0] * 10
moves = 0
for a in reversed(n):
	sum += int(a)
	count[int(a)] += 1
if sum >= k:
	print('0')
else:
	for i in range(10):
		if count[i] != 0 and (10 - i - 1) * count[i] + sum >= k:
			t = int((k - sum) / (10 - i - 1))
			if t * (10 - i - 1) + sum >= k:
				moves += t
			else:
				moves += t + 1
			break
		else:
			sum += count[i] * (10 - i - 1)
			moves += count[i]
	print(moves)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
k = int(input())
n = input()
A = [*n]
A = list(map(int, A))
t = sum(A)
if t >= k:
	print(0)
else:
	A.sort()
	B = []
	for i in A:
		B.append(9 - i)
	B = list(accumulate(B))
	x = bisect.bisect_left(B, k - t)
	print(x + 1)


k = int(input())
n = int(input())
l = [int(i) for i in str(n)]
s = sum(l)
if k <= s:
	print(0)
else:
	l.sort()
	p = k - s
	j = 0
	while j < len(l) and p > 0:
		p -= 9 - l[j]
		j += 1
	print(j)


k = int(input())
n = list(map(int, list(input())))
n.sort()
sum_ = sum(n)
for (cnt, elem) in enumerate(n):
	if sum_ >= k:
		print(cnt)
		break
	sum_ += 9 - elem
else:
	print(len(n))


import sys
it = iter(sys.stdin.read().splitlines())
k = int(next(it))
n = [int(x) for x in list(next(it))]
n.sort()
suma = sum(n)
respuesta = 0
while suma < k:
	suma += 9 - n.pop(0)
	respuesta += 1
print(respuesta)


k = int(input())
n = int(input())
l = len(str(n))
li = list(str(n))
s = 0
for i in range(l):
	s = s + int(li[i])
if s >= k:
	print(0)
else:
	c = 0
	x = abs(s - k)
	li.sort()
	for i in range(l):
		s = s - int(li[i]) + 9
		c += 1
		if s >= k:
			break
	print(c)


a = int(input())
b = input()
s = 0
x = []
o = 0
for i in b:
	s = s + int(i)
	x.append(9 - int(i))
x.sort()
x.reverse()
c = a - s
while c > 0:
	c = c - x[o]
	o = o + 1
print(o)


k = int(input())
n = input()
n_sum = sum([int(i) for i in n])
n_sorted = list(sorted(n))
if n_sum >= k:
	print(0)
else:
	remainder = k - n_sum
	nums = 0
	for ch in n_sorted:
		if remainder > 0:
			nums += 1
			remainder -= 9 - int(ch)
		else:
			break
	print(nums)


k = int(input())
n = input()
f = [0] * 10
for d in n:
	d = int(d)
	k -= d
	f[d] += 1
ans = 0
i = 9
while k > 0:
	a = min((k + i - 1) // i, f[9 - i])
	ans += a
	k -= a * i
	i -= 1
print(ans)


import sys
import math

def countDigits(n):
	digits = []
	for i in range(10):
		digits.append(n.count(str(i)))
	return digits

def sumDigits(digits):
	suma = 0
	for i in range(len(digits)):
		suma += digits[i] * i
	return suma

def getDigitsPon(digits, pos):
	digitsPon = []
	for i in range(10, pos, -1):
		digitsPon.append(digits[9 - 1] * i)
	return digitsPon

def minNumberOfDigits(n, k):
	digits = countDigits(n)
	diff = k - sumDigits(digits)
	if diff <= 0:
		return 0
	else:
		res = 0
		count = 0
		temp = 0
		while temp < diff:
			for i in range(digits[count]):
				temp += 9 - count
				res += 1
				if temp >= diff:
					break
			count += 1
		return res
(k, n) = list(sys.stdin.read().split())
result = minNumberOfDigits(n, int(k))
print(result)


x = input('')
x = int(x)
y = input('')
holder = []
counter = 0
add = 0
for i in y:
	add += int(i)
	holder.append(int(i))
holder.sort()
if add < x:
	while x > add:
		add += 9 - holder[counter]
		counter += 1
	print(counter)
else:
	print(0)


k = int(input())
n = input()
a = dict()
ans = 0
for i in range(10):
	a[i] = 0
for i in n:
	a[int(i)] += 1
	ans += int(i)
x = 0
for i in range(10):
	while a[i] > 0 and ans < k:
		x += 1
		a[i] -= 1
		ans += 9 - i
print(x)


while True:
	try:
		k = int(input())
		if k < 1 or k > 10000000000:
			raise ValueError
		break
	except ValueError:
		pass
while True:
	try:
		n = input()
		if len(n) < 1:
			raise ValueError
		break
	except ValueError:
		pass
digits = []
for char in n:
	digits.append(ord(char) - ord('0'))
digits.sort()
current = sum(digits)
ans = 0
for digit in digits:
	if current < k:
		current += 9 - digit
		ans += 1
print(ans)


k = int(input())
num = input()
a = []
digitsum = 0
for ch in num:
	digit = int(ch)
	a.append(digit)
	digitsum += digit
a.sort()
answer = 0
index = 0
while digitsum < k:
	digitsum += 9 - a[index]
	index += 1
print(index)


k = int(input())
n = list(map(int, list(input())))
bucket = [0 for _ in range(10)]
for i in n:
	bucket[i] += 1
s = 0
for i in range(10):
	s += i * bucket[i]
res = 0
while s < k:
	minnum = 0
	for i in range(10):
		if bucket[i] > 0:
			minnum = i
			bucket[i] -= 1
			break
	s += 9 - minnum
	res += 1
print(res)


k = int(input())
s = input()
l = list(map(int, s))
add = sum(l)
if add >= k:
	print(0)
else:
	l.sort()
	(count, i) = (0, 0)
	while add < k:
		add = add + 9 - l[i]
		i = i + 1
		count = count + 1
	print(count)


import math

def str_sum(n):
	return sum(map(int, list(n)))

def min_idx(n):
	minv = 10
	trace = [[] for i in range(10)]
	for (ni, nv) in enumerate(n):
		nv = int(nv)
		trace[nv].append(ni)
		if minv > nv:
			minv = nv
	return (trace, minv)

def main():
	k = int(input())
	n = list(input())
	origin = n[:]
	changed = 0
	sumv = str_sum(n)
	(miniss, minv) = min_idx(n)
	while sumv < k:
		minis = miniss[minv]
		dif = 9 - minv
		if dif * len(minis) + sumv >= k:
			delta = math.ceil((k - sumv) / dif)
			changed += delta
			sumv += delta * dif
		else:
			changed += len(minis)
			sumv += dif * len(minis)
		minv += 1
	print(changed)
main()


def solve(n, k):
	dig = []
	for d in n:
		dig.append(ord(d) - ord('0'))
	dig.sort()
	_sum = sum(dig)
	count = 0
	for d in dig:
		if _sum < k:
			_sum += 9 - d
			count += 1
	return count
k = int(input())
n = input()
print(solve(n, k))


k = int(input())
n = input()
a = []
for i in n:
	a.append(ord(i) - ord('0'))
a.sort()
c = sum(a)
ans = 0
for i in a:
	if c < k:
		c += 9 - i
		ans += 1
print(ans)


from bisect import bisect_left, bisect_right
from sys import stdin as fin
(k, n) = (int(fin.readline()), [int(sym) for sym in fin.readline().rstrip()])
dsum = sum(n)
n.sort()
i = 0
while dsum < k:
	dsum += 9 - n[i]
	i += 1
print(i)


x = int(input())
y = list(input())
y = [int(i) for i in y]
su = sum(y)
y.sort()
count = 0
for i in y:
	if su < x:
		su += 9 - i
		count += 1
	else:
		break
print(count)


k = int(input())
b = [0] * 10
sm = ans = 0
for i in input():
	b[int(i)] += 1
	sm += int(i)
while sm < k:
	for i in range(9):
		if b[i] > 0:
			ans += 1
			b[i] -= 1
			sm += 9 - i
			break
print(ans)


k = int(input())
s = input()
a = sorted((int(i) for i in s))
sm = sum(a)
i = 0
cnt = 0
if sm >= k:
	print('0')
else:
	x = k - sm
	while x > 0:
		x -= 9 - a[i]
		i += 1
		cnt += 1
	print(cnt)


k = int(input())
n = input()
x = []
nn = 0
d = 0
for i in range(len(n)):
	x.append(int(n[i]))
for m in range(len(n)):
	nn = nn + x[m]
if nn >= k:
	print('0')
else:
	x.sort()
	p = 0
	while nn < k:
		nn += 9 - x[p]
		p += 1
		d = d + 1
	print(d)


def main():
	k = int(input())
	digits = dict()
	for digit in '0123456789':
		digits[digit] = 0
	n = [int(d) for d in sorted(input().strip())]
	digit_sum = sum(n)
	k = k - digit_sum
	count = 0
	for d in n:
		if k <= 0 or d == 9:
			break
		k -= 9 - d
		count += 1
	return count
print(main())


from math import inf, sqrt, floor, ceil
from collections import Counter, defaultdict, deque
from heapq import heappush as hpush, heappop as hpop, heapify as h
from operator import itemgetter
from itertools import product
from bisect import bisect_left, bisect_right
k = int(input())
a = [int(i) for i in input()]
a.sort()
s = sum(a)
ans = 0
for i in range(len(a)):
	if s < k:
		s -= a[i]
		s += 9
		ans += 1
	else:
		break
print(ans)


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
k = ii()
s = input()
c = dd()
total = 0
for x in s:
	total += int(x)
	c[int(x)] += 1
if total >= k:
	exit(print(0))
res = 0
dif = k - total
for i in range(9):
	t = min(c[i], ceil(dif, 9 - i))
	dif -= t * (9 - i)
	res += t
	if dif <= 0:
		break
print(res)


k = int(input())
n = int(input())
digits = [0] * 10
suma = 0
for i in str(n):
	digits[int(i)] += 1
	suma += int(i)
answer = 0
while suma < k:
	minimum_i = 0
	for i in range(0, len(digits)):
		if digits[i] > 0:
			minimum_i = i
			digits[i] -= 1
			break
	answer += 1
	suma += 9 - minimum_i
print(answer)


def main():
	k = int(input())
	s = list(input())
	n = len(s)
	d = [0] * 10
	for i in range(n):
		d[int(s[i])] += 1
	a = 0
	for i in range(10):
		a += i * d[i]
	if k <= a:
		print(0)
		return
	i = 0
	c = 0
	while k > a:
		if d[i] == 0:
			i += 1
			continue
		a += 9 - i
		d[i] -= 1
		c += 1
	print(c)
main()


from sys import stdin, stdout

def main():
	global io
	io = Stdio()
	k = io.read_int()
	tmp = io.read()
	n = [ord(tmp[i]) - ord('0') for i in range(len(tmp))]
	s = 0
	for i in range(len(n)):
		s += n[i]
	n.sort()
	ans = 0
	for i in range(len(n)):
		if s >= k:
			break
		s += 9 - n[i]
		ans += 1
	print(ans)

class Stdio:
	index = 0
	tokens = []

	def read_line(self):
		return stdin.readline()[:-1]

	def read(self):
		while self.index >= len(self.tokens):
			self.tokens = self.read_line().strip().split()
			num_empty_lines = 0
			if self.tokens == []:
				return None
			self.index = 0
		token = self.tokens[self.index]
		self.index += 1
		return token

	def read_int(self):
		return int(self.read())

	def read_float(self):
		return float(self.read())

	def read_char(self):
		return chr(self.read())

	def print(self, *objectsToPrint):
		for _obj_ in objectsToPrint:
			stdout.write(str(_obj_))

	def println(self, *objectsToPrint):
		for _obj_ in objectsToPrint:
			stdout.write(str(_obj_))
		stdout.write('\n')
main()


k = int(input())
n = input()
counter = 0
somme = 0
ascending = ''.join(sorted(str(n)))
for i in range(len(n)):
	somme = somme + int(n[i])
if somme >= k:
	print(counter)
else:
	for j in range(len(n)):
		diff = 9 - int(ascending[j])
		somme = somme + diff
		counter = counter + 1
		if somme >= k:
			print(counter)
			break