N, M = map(int, input().split())
S = []
C = []
if M != 0:
    for l in range(M):
        S.append(0)
        C.append(0)
        S[l], C[l] = map(int, input().split())
        C[l] = str(C[l])
else:
    if N == 1:
        print(0)
        quit()
    elif N == 2:
        print(10)
        quit()
    elif N == 3:
        print(100)
        quit()

lst = [str(i) for i in range(10**N)]
for i in range(10**N):
    if len(lst[i]) != N:
        while len(lst[i]) < N:
            lst[i] = "0" + lst[i]

for x in range(M):	
    if S[x] == 1 and C[x] == "0":
        if N > 1:
            print(-1)
            quit()
        else:
            print(0)
            quit()

for n in range(10**N):
    for m in range(M):
        if lst[n][S[m]-1] != C[m]:
            lst[n] = "1000"
    lst[n] = int(lst[n])

if min(lst) == 1000:
    print(-1)
elif len(str(min(lst))) != N:
    print("1" + str(min(lst)))
else:
    print(min(lst))