n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

s = [0] * n
c = [0] * n
flag = True
for i in sc:
    if c[i[0]-1] > 0 and s[i[0]-1] != i[1]:
        flag = False
        break
    else:
        s[i[0]-1] = i[1]
        c[i[0]-1] += 1
if s[0] == 0:
    flag = False
s = ''.join(map(str, s))
print(s if flag else -1)