N, M = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for _ in range(M)]
if N == 1:
    minN = 0
if N == 2:
    minN = 10
if N == 3:
    minN = 100
N = int("9"*N) + 1
    
for i in range(minN, N):
    flag = True
    for j in S:
        tmp = str(i)
        s,c = j
        try:
            if not tmp[s-1] == str(c):
                flag = False
                break
        except IndexError:
            flag = False
            break
    if flag:
        ans = i
        break
    else:
        ans = False
if ans:
    print(ans)
else:
    print(-1)