import sys
n,m=map(int,input().split())
tmp=[0]*n
if m==0:
    print(-1)
for _ in range(m):
    s,c=map(int,input().split())
    if tmp[s-1]==0:
        tmp[s-1]=c
    elif s-1==0 and c==0:
        print(-1)
    else:
        if tmp[s-1]==c:
            continue
        else:
            print(-1)
        sys.exit()
print(100*tmp[0]+10*tmp[1]+tmp[2])