N,M =map(int, input().split())
a = [input().split() for l in range(M)]

for i in range(M):
    for j in range(2):
        a[i][j]=int(a[i][j])

a.sort()
for i in range(M-1):
    if a[i]==a[i+1]:
        a[i]=[0,0]
ans = 10**(N-1)

for i in range(M):
    if a[i][0]==1 ans a[i][1]!=0:
        ans += (a[i][1]-1)*10**(N-a[i][0])
    else:
        ans += a[i][1]*10**(N-a[i][0])

for i in range(M):
    for j in range(M-i):
        if a[i][0] == a[i+j][0] and a[i][1] != a[i+j][1]:
            ans = -1

for i in range(M):
    if a[i][0]==1 and a[i][1]==0:
        ans = -1

if M == 0 and N ==1:
    ans = 0

print(ans)