
N, M = map(int, input().split())

if N == 3:
    res =[1,0,0]
elif N == 2:
    res = [1, 0]
else:
    res = [1]

SC = []
for i in range(M):
    s, c = map(int, input().split())
    res[s-1] = c
    SC.append([s, c])

if N == 3:
    tmp = (res[0]*100) + (res[1]*10) + (res[2]*1)
elif N == 2:
    tmp = (res[0]*10) + (res[1]*10)
else:
    tmp = (res[0]*1)

ff = True
for sc in SC:
    s, c = sc[0], sc[1]
    if res[s-1] != c:
        ff = False
    if (s == 1) and (c == 0):
        ff = False
    
if ff == True:
    print(tmp)   
else:
    print(-1)