import sys
n, m = map(int, input().split())
isExist=True
li2 = [[''] for i in range(n)]
for i in range(m):
    s, c = map(int, input().split())
    if (li2[s - 1][0] != '' and li2[s - 1][0] != c):
        isExist = False
    elif(s == 1 and c == 0):
            isExist = False
    else:
        li2[s - 1][0] = c
ans=''
if (not isExist):
        print(-1)
        sys.exit()
else:
        print(0)
        sys.exit()
for i in range(n):
    if (li2[0][0] == ''):
        li2[0][0]=1
    if (li2[i][0] == ''):
        li2[i][0] = 0
for i in range(n):
    ans += str(li2[i][0])
if (n == 1 and m == 0):
    ans=0
print(int(ans))