import sys
N,M = map(int,input().split())
ls_1 = []
ls_2 = []
ls_3 = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ls_1.append(c)
    elif s == 2:
        ls_2.append(c)
    else:
        ls_3.append(c)
if len(set(ls_1)) > 1 or len(set(ls_2)) > 1 or len(set(ls_3)) > 1 or ls_1[0] == 0:
    print(-1)
    sys.exit()
if len(ls_1) == 0:
    ls_1.append(1)
if len(ls_2) == 0:
    ls_2.append(0)
if len(ls_3) == 0:
    ls_3.append(0)
    
ans = 100 * ls_1[0] + 10 * ls_2[0] + ls_3[0]
print(ans)