N,M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
x = [-1]*N
for s,c in sc:
    s -= 1
    if x[s] == -1 or x[s] == c:
        x[s] = c
    else:
        print(-1)
        quit()
if N!=1 and x[0]==0:
    print(-1)
    quit()
if x[0]==-1:
    x[0]=0
if N>=2 and x[1]==-1:
    x[1]=0
if N==3 and x[2]==-1:
    x[2]=0
print(int(''.join(list(map(str,x)))))