n, m = map(int, input().split())
tmp = ['*'] * m
is_ok = True
hoge = {}
for _ in range(m):
    s, c = input().split()
    if s in hoge and hoge[s] != c:
        is_ok = False
    else:
        hoge[s] = c
    tmp[int(s)-1] = c


# print(tmp)
num = ''.join(tmp)

num1 = int(num.replace('*', '0'))
num2 = int(num.replace('*', '1'))
if len(str(num1)) == n and is_ok:
    print(num1)
elif len(str(num2)) == n and is_ok:
    print(num2)
else:
    print('-1')
