import sys

n,m = map(int,input().split())
ans = [0]*n
l = []
for i in range(m):
    s,c = map(int,input().split())
    l.append([s,c])
for i in l:
    if i[0] == 1 and i[1] == 0:
        print(-1)
        sys.exit()
    if ans[i[0]-1] != 0 and ans[i[0]-1] != i[1]:
        print(-1)
        sys.exit()
    ans[i[0]-1] = i[1]

if ans[0] == 0:
    ans[0] = 1
t = ""
for i in ans:
    t += str(i)
print(int(t))