N, M = map(int, input().split())
s = [list(map(int, input().split()))for _ in range(M)]

num = [0]*N
for i in s:
    if num[i[0]-1] == 0 or num[i[0]-1] == i[1]:
        num[i[0]-1] = i[1]
    elif num[i[0]-1] != 0:
        print(-1)
        exit()
if num[0] == 0:
    print(-1)
    exit()
num = [str(_) for _ in num]
print(''.join(num))
