n, m = map(int, input().split())
tmp = [-1]*n
for _ in range(m):
    s, c = map(int, input().split())
    if tmp[s-1] == -1:
        tmp[s-1] = c
    else:
        if tmp[s-1] != c:
            print(-1)
            exit()

ans = []
for a in tmp:
    if a == -1:
        ans.append('0')
    else:
        ans.append(str(a))


ans = str(int(''.join(ans)))
if len(ans) != n:
    print(-1)
else:
    print(ans)