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

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