n,m = (int(x) for x in input().split())
#S = []
#C = []
x = [-1] * n
res = -1
for i in range(m):
    s,c = (int(a) for a in input().split())
    #S.append(s)
    #C.append(c)
    if not(x[s-1] == -1) and not(x[s-1] == c):
        break
    else:
        x[s-1] = c
else:
    if x[0] != 0:
        res = 0
        for i in range(len(x)):
            if x[i] == -1:
                th = 0
            else:
                th = x[i]
            res *= 10
            res += th
        
print(res)

    


