n, m = map(int, input().split())

list_A = []
for i in range(m):
    list_A.append(list(map(int, input().split())))

s = "0"*n
for i in list_A:
    # nが桁の場所，Mが数
    a, b = i
    
    # 桁に応じて変換
    s = s[:a-1] + str(b) + s[a:]

s1 = s

s = "0"*n
for i in reversed(list_A):
    # nが桁の場所，Mが数
    a, b = i
    
    # 桁に応じて変換
    s = s[:a-1] + str(b) + s[a:]

s2 = s

if s1 != s2 or s1[0] == "0" or s2[0] == "0":
    print(-1)
    exit()

if n > 1 and s1[0] == "0" or s2[0] == "0":
    print(-1)
    exit()

print(s)