n, m = map(int, input().split())
num = [0]*n

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


ans = int(''.join(map(str, num)))

if len(str(ans)) == n:
    print(ans)
else:
    print(-1)