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

def ng():
    print(-1)
    exit()

    
ans = [0] * n
sc = []
frst = True
for i in range(m):
    x = list(map(int, input().split()))
    if x[0] == 1:
        frst = False
    sc.append(x)

if frst:
    ans[0] = 1
sc.sort()
if sc[0][1] == 0:
    ng()
for i in range(1, m):
    if (sc[i][0] == sc[i - 1][0]) and (sc[i][1] != sc[i - 1][1]):
        ng() 

for i in range(m):
    ans[sc[i][0] - 1] = sc[i][1]

print(*ans, sep='')
