n, m = map(int, input().split())
num = [-1 for i in range(n)]
for i in range(m):
    s, c = input().split()
    s = int(s) -1
    if num[s] == -1: num[s] = c
    elif num[s] == c: continue
    else:
        num = [-1]
        break
joined_num = ''
for i in num:
    joined_num += '0' if i == -1 else i
num = int(joined_num)
if len(str(num)) != n: num = -1
print(num)