n, m = map(int, input().split())
tmp = ['a'] * n
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(hoge)


num = ''.join(tmp).replace('a', '0')
num = int(num)

# print(is_ok)
if len(str(num)) == n and is_ok:
    print(num)
else:
    print('-1')
