
N, M = map(int,input().split())
L = []
for i in range(M):
    s, c = map(int,input().split())
    L.append([s,c])
L2 = sorted(L)

F = []
S = ""
s1_0 = False
for i in range(len(L2)):
    if L2[i][0] == 1:
        S += str(L2[i][1])
        break
    else:
        s1_0 = True
s2_0 = False
for i in range(len(L2)):
    if L2[i][0] == 2 and s1_0 == False:
        S += str(L2[i][1])
        break
    elif L2[i][0] == 2 and s1_0 == True:
        if L2[i][1] != 0:
            S += str(L2[i][1])
            break
    elif s1_0 == False:
        S += str(L2[i][1])
        break
    else:
        s2_0 = True
for i in range(len(L2)):
    if L2[i][0] == 1:
        S += str(L2[i][1])
        break

Si = int(S)
if N == 3:
    if Si < 100:
        print(-1)
    else:
        print(Si)
elif N == 2:
    if Si < 10 or Si >= 100:
        print(-1)
    else:
        print(Si)
elif N == 1:
    if Si >= 10 or Si == 0:
        print(-1)
    else:
        print(Si)