N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
c = [i[1] for i in sc]
s = [i[0] for i in sc]
smax = max(s)
sc2 = [-1 for i in range(smax)]
flag = False
for s1,c1 in sc:
    if sc2[s1-1] == -1:
        sc2[s1-1] = c1
    else:
        flag = True
        break
if -1 in sc2:
    num = 0
else:
    num = int(''.join(map(str,sc2)))
if smax > N or flag or num == 0:
    print(-1)
else:
    if N == 1:
        if num <= 9:
            print(num)
    else:
        rem = N-smax
        print(str(num) + '0'*rem)
        