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 (num[0] == 0):
    if n > 1:
        print(-1)
    else:
        print(0)
    sys.exit()
elif num[0] == 10:
    num[0] = 1
num = [0 if i==10 else i for i in num]
ans = ''
for i in range(n):
    ans += str(num[i])
print(int(ans))



