N, M = map(int, input().split()) 
ans = ['', '', '']
if M == 0:
    print(0)
    exit()
for i in range(M):
    s, c = input().split()
    s = int(s)-1
    if ans[s] in ['', c]:
        ans[s] = c
    else:
        print(-1)
        exit()

if ans[0] == '0' and N >1:
    ans = -1
 
elif ans[0] == '' and ans[1] == '0' and N == 3:
    ans = -1

if ans == -1:
    print(ans)
    exit()

if ans[1] == '':
    ans[1] = '0'
if ans[2] == '':
    ans[2] = '0'

if N == 2:
    ans.pop()
if N == 1:
    ans = ans[0]

print(''.join(ans))