N, M = map(int, input().split())
S = [[0]*2 for _ in range(M)]
for i in range(M):
    S[i][0], S[i][1] = map(int, input().split())

sa = 0
Flg = True

for j in range(M):
    for k in range(j+1, M):
        if(S[j][0] == S[k][0]):
            if(S[j][1] != S[k][1]):
                Flg = False
S = list(map(list, set(map(tuple, S))))

if(Flg == True):
    for i in range(len(S)):
        if(S[i][0] == 2 and S[i][1] == 0):
            continue
        else:
            sa += (10**(3-S[i][0]))*S[i][1]
    if(len(str(sa)) == N):
        print(sa)
    else:
        print(-1)
else:
    print(-1)    