import sys 
n, m = map(int,input().split())
s = []
num = [10]*n
al = []
if m == 0:
    if n>1:
        print(-1)
    else:
        print(0)
    sys.exit()
for _ in range(m):
    s,c = map(int,input().split())
    if (s in al) & (num[s-1]!=c):
        print(-1)
        sys.exit()
    elif num[s-1]==10:
        num[s-1] = c
        al.append(s)

if n == 1:
    if (num[0]==10)|(num[0]==0):
        print(0)
        sys.exit()
    else:
        print(num[0])
        sys.exit()
elif n==2:
    if (num[0]==0):
        print(-1)
        sys.exit()
    elif (num[0]==10):
        num[0] == 1
    if (num[1]==10):
        num[1] = 0
    print(int(str(num[0])+str(num[1])))
elif n == 3:
    if (num[0]==0):
        print(-1)
        sys.exit()
    elif (num[0]==10):
        num[0] == 1
    if (num[1]==10):
        num[1] = 0
    if (num[2]==10):
        num[2] = 0
    print(int(str(num[0])+str(num[1])+str(num[1])))




