n, m = map(int, input().split())

res = [0]*n

l = [list(map(int, input().split())) for _ in range(m)]
for i in range(m-1):
    for j in range(i+1, m):
        if l[i][0]==l[j][0] and l[i][1]!= l[j][1]:
            print(-1)
            exit()

for x,y in l:
    if x==1 and y==0 and n!=1:
        print(-1)
        exit()

for x,y in l:
    res[x-1] = y
res = list(map(str, res))
print(''.join(res))
