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

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

lst = [[] for _ in range(n)]

for i in sc:
    lst[i[0] -1].append(i[1])

ans = ''

if lst[0] == []:
    ans += '1'
elif len(set(lst[0])) == 1:
    if lst[0][0] == 0:
        print(-1)
        exit()
    else:
        ans += str(lst[0][0])
else:
    print(-1)
    exit()

for i in range(n-1):
    if lst[i + 1] == []:
        ans += '0'
    elif len(set(lst[i +1])) == 1:
        ans += str(lst[i+1][0])
    else:
        print(-1)
        exit()

print(ans)