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

num = [0]*n
sf = [False]*n
if m==0:
    if n == 1:
        print(0)
    else:
        print(-1)
    exit()

for i in range(m):
    s, c = map(int,input().split())
    if (num[s-1] == c) or sf[s-1]==False:
        num[s-1] = c
        sf[s-1] = True
    else:
        print(-1)
        exit()
if sf[0]==True and n!=1:
    print(-1)
    exit()
else:
    if sf[0]==False:
        num[0]=1
    print("".join(map(str,num)))