N,M = list(map(int,input().split()))
ans = list('aaa')
flag = 0
for i in range(M):
    s,c = list(input().split())
    s = int(s)
    if ans[s-1] != 'a' and ans[s-1] != c:
        flag = -1
    else:
        ans[s-1] = c
for i in range(3):
    if ans[i] == 'a':
        ans[i] = '0'
ans_num = int("".join(ans))
if ans_num // 10**(N-1) ==0:
    flag = -1
if flag == -1:
    print(flag)
else:
    print(ans_num)
