# BOJ - 1107
n = input()
nn = len(n)
m = int(input())
if n == '100': print(0);exit()
if m == 0: print(min(abs(int(n)-100), nn));exit()
l = [i for i in range(10)]
for i in map(int, input().split()):
    l.remove(i)
a, b = min(l), max(l)
if m == 10: print(abs(int(n)-100));exit()
p, q = '', ''
if n[0] == '1':pass
"""
5457
3
6 7 8

100
5
0 1 2 3 4

500000
8
0 2 3 4 6 7 8 9
"""
42934bbaa29a895e9bab0fc9ecd8a28483cdab53
<mask token>

<mask token>
if n == '100':
    print(0)
    exit()
if m == 0:
    print(min(abs(int(n) - 100), nn))
    exit()
<mask token>
for i in map(int, input().split()):
    l.remove(i)
<mask token>
if m == 10:
    print(abs(int(n) - 100))
    exit()
<mask token>
if n[0] == '1':
    pass
<mask token>

n = input()
nn = len(n)
m = int(input())
if n == '100':
    print(0)
    exit()
if m == 0:
    print(min(abs(int(n) - 100), nn))
    exit()
l = [i for i in range(10)]
for i in map(int, input().split()):
    l.remove(i)
a, b = min(l), max(l)
if m == 10:
    print(abs(int(n) - 100))
    exit()
p, q = '', ''
if n[0] == '1':
    pass
<mask token>

# BOJ - 1107
n = input()
nn = len(n)
m = int(input())
if n == '100': print(0);exit()
if m == 0: print(min(abs(int(n)-100), nn));exit()
l = [i for i in range(10)]
for i in map(int, input().split()):
    l.remove(i)
a, b = min(l), max(l)
if m == 10: print(abs(int(n)-100));exit()
p, q = '', ''
if n[0] == '1':pass
"""
5457
3
6 7 8

100
5
0 1 2 3 4

500000
8
0 2 3 4 6 7 8 9
"""