N, M = map(int, input().split())
result = True
a = [0 for i in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if a[s-1] == 0:
        a[s-1] = c
    elif a[s-1] == c:
        pass
    else:
        result = False

if result is False:
    print(-1)
else:
    print(int(''.join(map(str, a))))