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

d = {}
for _ in range(m):
    s, c = input().split()
    s = int(s)-1
    if s not in d or d[s] == c:
        d[s] = c
    else:
        print(-1)
        exit()

for i in range(10**(n-1), 10**n):
    i = str(i)
    if all(i[s] == c for s, c in d.items()):
        print(i)
        exit()